pack-objects: use strcspn(3) in name_cmp_len()
Call strcspn(3) to find the length of a string terminated by NUL, NL or slash instead of open-coding it. Adopt its return type, size_t, to support strings of arbitrary length. Use that type in callers as well for variables and function parameters that receive the return value. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
1b4a38d741
commit
e65b868d07
@ -1708,17 +1708,14 @@ static void pbase_tree_put(struct pbase_tree_cache *cache)
|
|||||||
free(cache);
|
free(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int name_cmp_len(const char *name)
|
static size_t name_cmp_len(const char *name)
|
||||||
{
|
{
|
||||||
int i;
|
return strcspn(name, "\n/");
|
||||||
for (i = 0; name[i] && name[i] != '\n' && name[i] != '/'; i++)
|
|
||||||
;
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void add_pbase_object(struct tree_desc *tree,
|
static void add_pbase_object(struct tree_desc *tree,
|
||||||
const char *name,
|
const char *name,
|
||||||
int cmplen,
|
size_t cmplen,
|
||||||
const char *fullname)
|
const char *fullname)
|
||||||
{
|
{
|
||||||
struct name_entry entry;
|
struct name_entry entry;
|
||||||
@ -1743,7 +1740,7 @@ static void add_pbase_object(struct tree_desc *tree,
|
|||||||
struct tree_desc sub;
|
struct tree_desc sub;
|
||||||
struct pbase_tree_cache *tree;
|
struct pbase_tree_cache *tree;
|
||||||
const char *down = name+cmplen+1;
|
const char *down = name+cmplen+1;
|
||||||
int downlen = name_cmp_len(down);
|
size_t downlen = name_cmp_len(down);
|
||||||
|
|
||||||
tree = pbase_tree_get(&entry.oid);
|
tree = pbase_tree_get(&entry.oid);
|
||||||
if (!tree)
|
if (!tree)
|
||||||
@ -1795,7 +1792,7 @@ static int check_pbase_path(unsigned hash)
|
|||||||
static void add_preferred_base_object(const char *name)
|
static void add_preferred_base_object(const char *name)
|
||||||
{
|
{
|
||||||
struct pbase_tree *it;
|
struct pbase_tree *it;
|
||||||
int cmplen;
|
size_t cmplen;
|
||||||
unsigned hash = pack_name_hash(name);
|
unsigned hash = pack_name_hash(name);
|
||||||
|
|
||||||
if (!num_preferred_base || check_pbase_path(hash))
|
if (!num_preferred_base || check_pbase_path(hash))
|
||||||
|
Loading…
Reference in New Issue
Block a user