From: Junio C Hamano Date: Tue, 18 Mar 2014 20:51:02 +0000 (-0700) Subject: Merge branch 'mh/simplify-cache-tree-find' X-Git-Tag: v2.0.0-rc0~91 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/da2e0579adad88136b8a0a850d7325c398a401ac?ds=inline;hp=-c Merge branch 'mh/simplify-cache-tree-find' * mh/simplify-cache-tree-find: cache_tree_find(): use path variable when passing over slashes cache_tree_find(): remove early return cache_tree_find(): remove redundant check cache_tree_find(): fix comment formatting cache_tree_find(): find the end of path component using strchrnul() cache_tree_find(): remove redundant checks --- da2e0579adad88136b8a0a850d7325c398a401ac diff --combined cache-tree.c index 30149d1c42,7f8d74dbcd..587b35362f --- a/cache-tree.c +++ b/cache-tree.c @@@ -75,7 -75,11 +75,7 @@@ static struct cache_tree_sub *find_subt return NULL; pos = -pos-1; - if (it->subtree_alloc <= it->subtree_nr) { - it->subtree_alloc = alloc_nr(it->subtree_alloc); - it->down = xrealloc(it->down, it->subtree_alloc * - sizeof(*it->down)); - } + ALLOC_GROW(it->down, it->subtree_nr + 1, it->subtree_alloc); it->subtree_nr++; down = xmalloc(sizeof(*down) + pathlen + 1); @@@ -550,22 -554,19 +550,19 @@@ static struct cache_tree *cache_tree_fi const char *slash; struct cache_tree_sub *sub; - slash = strchr(path, '/'); - if (!slash) - slash = path + strlen(path); - /* between path and slash is the name of the - * subtree to look for. + slash = strchrnul(path, '/'); + /* + * Between path and slash is the name of the subtree + * to look for. */ sub = find_subtree(it, path, slash - path, 0); if (!sub) return NULL; it = sub->cache_tree; - if (slash) - while (*slash && *slash == '/') - slash++; - if (!slash || !*slash) - return it; /* prefix ended with slashes */ + path = slash; + while (*path == '/') + path++; } return it; }