Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Unified Diff: url/third_party/mozilla/url_parse.cc

Issue 2549583004: [url] Early return for finding query/ref parts in path parsing (Closed)
Patch Set: minor code move (trybots prev) Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: url/third_party/mozilla/url_parse.cc
diff --git a/url/third_party/mozilla/url_parse.cc b/url/third_party/mozilla/url_parse.cc
index ba842b87b5db347ccc3bc5f5dccf7472ffc1aa40..60aeb059d7199bfa08e987d330a15f81df475346 100644
--- a/url/third_party/mozilla/url_parse.cc
+++ b/url/third_party/mozilla/url_parse.cc
@@ -175,6 +175,31 @@ void DoParseAuthority(const CHAR* spec,
}
}
+template <typename CHAR>
+inline void FindQueryAndRefParts(const CHAR* spec,
+ const Component& path,
+ int* query_separator,
+ int* ref_separator) {
+ int path_end = path.begin + path.len;
+ for (int i = path.begin; i < path_end; i++) {
+ switch (spec[i]) {
+ case '?':
+ // Only match the query string if it precedes the reference fragment
+ // and when we haven't found one already.
+ if (*query_separator < 0)
+ *query_separator = i;
+ break;
+ case '#':
+ // Record the first # sign only.
+ if (*ref_separator < 0) {
+ *ref_separator = i;
+ return;
+ }
+ break;
+ }
+ }
+}
+
template<typename CHAR>
void ParsePath(const CHAR* spec,
const Component& path,
@@ -193,25 +218,9 @@ void ParsePath(const CHAR* spec,
DCHECK(path.len > 0) << "We should never have 0 length paths";
// Search for first occurrence of either ? or #.
- int path_end = path.begin + path.len;
-
int query_separator = -1; // Index of the '?'
int ref_separator = -1; // Index of the '#'
- for (int i = path.begin; i < path_end; i++) {
- switch (spec[i]) {
- case '?':
- // Only match the query string if it precedes the reference fragment
- // and when we haven't found one already.
- if (ref_separator < 0 && query_separator < 0)
- query_separator = i;
- break;
- case '#':
- // Record the first # sign only.
- if (ref_separator < 0)
- ref_separator = i;
- break;
- }
- }
+ FindQueryAndRefParts(spec, path, &query_separator, &ref_separator);
// Markers pointing to the character after each of these corresponding
// components. The code below words from the end back to the beginning,
@@ -219,6 +228,7 @@ void ParsePath(const CHAR* spec,
int file_end, query_end;
// Ref fragment: from the # to the end of the path.
+ int path_end = path.begin + path.len;
if (ref_separator >= 0) {
file_end = query_end = ref_separator;
*ref = MakeRange(ref_separator + 1, path_end);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698