diff options
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | 2013-01-16 02:08:16 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-01-16 09:48:36 -0800 |
commit | c971ddfdcd319fb5cad95aa7047c54ebe6a22d1a (patch) | |
tree | 0a0719639eac07c63af594fb9bc138a2e25a7999 /refs.c | |
parent | e1980c9d23c22ecfbcadbe91d304ba778b84b457 (diff) | |
download | git-c971ddfdcd319fb5cad95aa7047c54ebe6a22d1a.tar.gz git-c971ddfdcd319fb5cad95aa7047c54ebe6a22d1a.tar.xz |
refs: use strncmp() instead of strlen() and memcmp()
Simplify ref_entry_cmp_sslice() by using strncmp() to compare the
length-limited key and a NUL-terminated entry. While we're at it,
retain the const attribute of the input pointers.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.c')
-rw-r--r-- | refs.c | 10 |
1 files changed, 4 insertions, 6 deletions
@@ -322,14 +322,12 @@ struct string_slice { static int ref_entry_cmp_sslice(const void *key_, const void *ent_) { - struct string_slice *key = (struct string_slice *)key_; - struct ref_entry *ent = *(struct ref_entry **)ent_; - int entlen = strlen(ent->name); - int cmplen = key->len < entlen ? key->len : entlen; - int cmp = memcmp(key->str, ent->name, cmplen); + const struct string_slice *key = key_; + const struct ref_entry *ent = *(const struct ref_entry * const *)ent_; + int cmp = strncmp(key->str, ent->name, key->len); if (cmp) return cmp; - return key->len - entlen; + return '\0' - (unsigned char)ent->name[key->len]; } /* |