Merge branch 'mh/simplify-cache-tree-find'
authorJunio C Hamano <gitster@pobox.com>
Tue, 18 Mar 2014 20:51:02 +0000 (13:51 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 18 Mar 2014 20:51:02 +0000 (13:51 -0700)
* 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

1  2 
cache-tree.c
diff --combined cache-tree.c
index 30149d1c42f94cf28e10db317ad3337c8e534ae1,7f8d74dbcdb6079f12217b24afee3ccbcb05005a..587b35362f18b3e98cd9e201a2de37c1878e852b
@@@ -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;
  }