Merge branch 'jm/dedup-name-compare'

* jm/dedup-name-compare:
  cleanup duplicate name_compare() functions
  name-hash.c: replace cache_name_compare() with memcmp(3)
This commit is contained in:
Junio C Hamano 2014-06-25 12:23:57 -07:00
commit 597072314c
6 changed files with 16 additions and 35 deletions

View File

@ -999,7 +999,7 @@ extern int validate_headref(const char *ref);
extern int base_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
extern int df_name_compare(const char *name1, int len1, int mode1, const char *name2, int len2, int mode2);
extern int cache_name_compare(const char *name1, int len1, const char *name2, int len2);
extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
extern void *read_object_with_reference(const unsigned char *sha1,

3
dir.c
View File

@ -1354,8 +1354,7 @@ static int cmp_name(const void *p1, const void *p2)
const struct dir_entry *e1 = *(const struct dir_entry **)p1;
const struct dir_entry *e2 = *(const struct dir_entry **)p2;
return cache_name_compare(e1->name, e1->len,
e2->name, e2->len);
return name_compare(e1->name, e1->len, e2->name, e2->len);
}
static struct path_simplify *create_simplify(const char **pathspec)

View File

@ -179,7 +179,7 @@ static int same_name(const struct cache_entry *ce, const char *name, int namelen
* Always do exact compare, even if we want a case-ignoring comparison;
* we do the quick exact one first, because it will be the common case.
*/
if (len == namelen && !cache_name_compare(name, namelen, ce->name, len))
if (len == namelen && !memcmp(name, ce->name, len))
return 1;
if (!icase)

View File

@ -422,18 +422,26 @@ int df_name_compare(const char *name1, int len1, int mode1,
return c1 - c2;
}
int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
int name_compare(const char *name1, size_t len1, const char *name2, size_t len2)
{
int len = len1 < len2 ? len1 : len2;
int cmp;
cmp = memcmp(name1, name2, len);
size_t min_len = (len1 < len2) ? len1 : len2;
int cmp = memcmp(name1, name2, min_len);
if (cmp)
return cmp;
if (len1 < len2)
return -1;
if (len1 > len2)
return 1;
return 0;
}
int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
{
int cmp;
cmp = name_compare(name1, len1, name2, len2);
if (cmp)
return cmp;
if (stage1 < stage2)
return -1;
@ -442,11 +450,6 @@ int cache_name_stage_compare(const char *name1, int len1, int stage1, const char
return 0;
}
int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
{
return cache_name_stage_compare(name1, len1, 0, name2, len2, 0);
}
static int index_name_stage_pos(const struct index_state *istate, const char *name, int namelen, int stage)
{
int first, last;

View File

@ -144,16 +144,6 @@ struct tree_desc_x {
struct tree_desc_skip *skip;
};
static int name_compare(const char *a, int a_len,
const char *b, int b_len)
{
int len = (a_len < b_len) ? a_len : b_len;
int cmp = memcmp(a, b, len);
if (cmp)
return cmp;
return (a_len - b_len);
}
static int check_entry_match(const char *a, int a_len, const char *b, int b_len)
{
/*

View File

@ -622,17 +622,6 @@ static int unpack_failed(struct unpack_trees_options *o, const char *message)
return -1;
}
/* NEEDSWORK: give this a better name and share with tree-walk.c */
static int name_compare(const char *a, int a_len,
const char *b, int b_len)
{
int len = (a_len < b_len) ? a_len : b_len;
int cmp = memcmp(a, b, len);
if (cmp)
return cmp;
return (a_len - b_len);
}
/*
* The tree traversal is looking at name p. If we have a matching entry,
* return it. If name p is a directory in the index, do not return