Strip namelen out of ce_flags into a ce_namelen field
Strip the name length from the ce_flags field and move it
into its own ce_namelen field in struct cache_entry. This
will both give us a tiny bit of a performance enhancement
when working with long pathnames and is a refactoring for
more readability of the code.
It enhances readability, by making it more clear what
is a flag, and where the length is stored and make it clear
which functions use stages in comparisions and which only
use the length.
It also makes CE_NAMEMASK private, so that users don't
mistakenly write the name length in the flags.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Thomas Gummerer13 years agocommitted byJunio C Hamano
@ -395,17 +399,10 @@ int df_name_compare(const char *name1, int len1, int mode1,
@@ -395,17 +399,10 @@ int df_name_compare(const char *name1, int len1, int mode1,
return c1 - c2;
}
int cache_name_compare(const char *name1, int flags1, const char *name2, int flags2)
int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2)
{
int len1, len2, len, cmp;
len1 = flags1 & CE_NAMEMASK;
if (CE_NAMEMASK <= len1)
len1 = strlen(name1 + CE_NAMEMASK) + CE_NAMEMASK;
len2 = flags2 & CE_NAMEMASK;
if (CE_NAMEMASK <= len2)
len2 = strlen(name2 + CE_NAMEMASK) + CE_NAMEMASK;
len = len1 < len2 ? len1 : len2;
int len = len1 < len2 ? len1 : len2;
int cmp;
cmp = memcmp(name1, name2, len);
if (cmp)
@ -415,18 +412,19 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
@@ -415,18 +412,19 @@ int cache_name_compare(const char *name1, int flags1, const char *name2, int fla
if (len1 > len2)
return 1;
/* Compare stages */
flags1 &= CE_STAGEMASK;
flags2 &= CE_STAGEMASK;
if (flags1 < flags2)
if (stage1 < stage2)
return -1;
if (flags1 > flags2)
if (stage1 > stage2)
return 1;
return 0;
}
int index_name_pos(const struct index_state *istate, const char *name, int namelen)
int cache_name_compare(const char *name1, int len1, const char *name2, int len2)
@ -22,7 +22,8 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b
@@ -22,7 +22,8 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b