diff options
author | Nico Weber <thakis@chromium.org> | 2012-05-03 23:13:40 (GMT) |
---|---|---|
committer | Nico Weber <thakis@chromium.org> | 2012-05-04 01:12:21 (GMT) |
commit | 8be4ffbaac5e88bf4da8e537ffdbecccbb916170 (patch) | |
tree | e49eebaa873602e046272b9209f1a8d7d83b492b /src/util.cc | |
parent | 3253f66fd14fce3278f71b29a22d61bf1b4aa9f5 (diff) | |
download | Ninja-8be4ffbaac5e88bf4da8e537ffdbecccbb916170.zip Ninja-8be4ffbaac5e88bf4da8e537ffdbecccbb916170.tar.gz Ninja-8be4ffbaac5e88bf4da8e537ffdbecccbb916170.tar.bz2 |
Speed up CanonicalizePath() 6.8% (322ms -> 300ms for chrome empty build).
Diffstat (limited to 'src/util.cc')
-rw-r--r-- | src/util.cc | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/util.cc b/src/util.cc index 73f13f8..6bafc91 100644 --- a/src/util.cc +++ b/src/util.cc @@ -113,29 +113,30 @@ bool CanonicalizePath(char* path, int* len, string* err) { } while (src < end) { - const char* sep = (const char*)memchr(src, '/', end - src); - if (sep == NULL) - sep = end; - if (*src == '.') { - if (sep - src == 1) { + if (src[1] == '/' || src + 1 == end) { // '.' component; eliminate. src += 2; continue; - } else if (sep - src == 2 && src[1] == '.') { + } else if (src[1] == '.' && (src[2] == '/' || src + 2 == end)) { // '..' component. Back up if possible. if (component_count > 0) { dst = components[component_count - 1]; src += 3; --component_count; } else { - while (src <= sep) - *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; + *dst++ = *src++; } continue; } } + const char* sep = (const char*)memchr(src, '/', end - src); + if (sep == NULL) + sep = end; + if (sep > src) { if (component_count == kMaxPathComponents) Fatal("path has too many components"); |