Don't walk path components twice. Speeds up CanonicalizePath() 115ms (285ms -> 170ms).
authorNico Weber <thakis@chromium.org>
Fri, 4 May 2012 01:18:03 +0000 (18:18 -0700)
committerNico Weber <thakis@chromium.org>
Fri, 4 May 2012 01:18:03 +0000 (18:18 -0700)
src/util.cc

index de535b3d8ebd61bfcc96e33c8c59172fdea02767..49b079cb60c52a6fdd2481b9936401663c94b500 100644 (file)
@@ -143,13 +143,9 @@ bool CanonicalizePath(char* path, int* len, string* err) {
     components[component_count] = dst;
     ++component_count;
 
-    const char* sep = (const char*)memchr(src, '/', end - src);
-    if (sep == NULL)
-      sep = end;
-    while (src <= sep) {
+    while (*src != '/' && src != end)
       *dst++ = *src++;
-    }
-    src = sep + 1;
+    *dst++ = *src++;  // Copy '/' or final \0 character as well.
   }
 
   if (dst == start) {