From e405f07e52417b5be95094d0f1f8a23e30ec956f Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 3 May 2012 18:18:03 -0700 Subject: Don't walk path components twice. Speeds up CanonicalizePath() 115ms (285ms -> 170ms). --- src/util.cc | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/util.cc b/src/util.cc index de535b3..49b079c 100644 --- a/src/util.cc +++ b/src/util.cc @@ -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) { -- cgit v0.12