com php-src: Cleanup parse_url() gotos: ext/standar d/url.c

From: Date: Tue, 22 Nov 2016 18:24:21 +0000
Subject: com php-src: Cleanup parse_url() gotos: ext/standar d/url.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-95991@lists.php.net to get a copy of this message
Commit: 9befad6fc2abe124c1eab80e3dc33e044d3d5db2 Author: Nikita Popov <nikic@php.net> Thu, 17 Nov 2016 23:18:05 +0100 Parents: 3e4538590384f1736c483b1f24bf3d79e0adcbe9 Branches: PHP-5.6 PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=9befad6fc2abe124c1eab80e3dc33e044d3d5db2 Log: Cleanup parse_url() gotos Simplify some unnecessarily complicated code. In particular the length updates are unnecessary (length is only used at the very start) and we're goto'ing around a bit too much. Changed paths: M ext/standard/url.c Diff: diff --git a/ext/standard/url.c b/ext/standard/url.c index 9627184..94b9f20 100644 --- a/ext/standard/url.c +++ b/ext/standard/url.c @@ -122,7 +122,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) if (*(e + 1) == '\0') { /* only scheme is available */ ret->scheme = estrndup(s, (e - s)); php_replace_controlchars_ex(ret->scheme, (e - s)); - goto end; + return ret; } /* @@ -145,8 +145,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) ret->scheme = estrndup(s, (e-s)); php_replace_controlchars_ex(ret->scheme, (e - s)); - length -= ++e - s; - s = e; + s = e + 1; goto just_path; } else { ret->scheme = estrndup(s, (e-s)); @@ -162,18 +161,12 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) if (*(e + 5) == ':') { s = e + 4; } - goto nohost; + goto just_path; } } } else { - if (!strncasecmp("file", ret->scheme, sizeof("file"))) { - s = e + 1; - goto nohost; - } else { - length -= ++e - s; - s = e; - goto just_path; - } + s = e + 1; + goto just_path; } } } else if (e) { /* no scheme; starts with colon: look for port */ @@ -212,9 +205,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) } else if (*s == '/' && *(s + 1) == '/') { /* relative-scheme URL */ s += 2; } else { - just_path: - ue = s + length; - goto nohost; + goto just_path; } e = s + strcspn(s, "/?#"); @@ -296,7 +287,7 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) s = e; - nohost: + just_path: if ((p = memchr(s, '?', (ue - s)))) { pp = memchr(s, '#', (ue - s)); @@ -343,7 +334,6 @@ PHPAPI php_url *php_url_parse_ex(char const *str, int length) ret->path = estrndup(s, (ue-s)); php_replace_controlchars_ex(ret->path, (ue - s)); } -end: return ret; } /* }}} */

« previous php.cvs (#95991) next »