use fspathhash() everywhere

cf2dc1c238 (speed up alt_odb_usable() with many alternates, 2021-07-07) introduced the function fspathhash() for calculating path hashes while respecting the configuration option core.ignorecase. Call it instead of open-coding it; the resulting code is shorter and less repetitive. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 30, 2021 at 21:06 UTC 74318423259b265cf95112355be254fa21d4a6f9
3 files changed +8 -26
builtin/sparse-checkout.c
+2 -8
@@ -380,10 +380,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
380 struct pattern_entry *e = xmalloc(sizeof(*e));
381 e->patternlen = path->len;
382 e->pattern = strbuf_detach(path, NULL);
383 - hashmap_entry_init(&e->ent,
384 - ignore_case ?
385 - strihash(e->pattern) :
386 - strhash(e->pattern));
383 + hashmap_entry_init(&e->ent, fspathhash(e->pattern));
384
385 hashmap_add(&pl->recursive_hashmap, &e->ent);
386
@@ -399,10 +396,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
396 e = xmalloc(sizeof(struct pattern_entry));
397 e->patternlen = newlen;
398 e->pattern = xstrndup(oldpattern, newlen);
402 - hashmap_entry_init(&e->ent,
403 - ignore_case ?
404 - strihash(e->pattern) :
405 - strhash(e->pattern));
399 + hashmap_entry_init(&e->ent, fspathhash(e->pattern));
400
401 if (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL))
402 hashmap_add(&pl->parent_hashmap, &e->ent);
dir.c
+3 -10
@@ -782,9 +782,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
782 translated->pattern = truncated;
783 translated->patternlen = given->patternlen - 2;
784 hashmap_entry_init(&translated->ent,
785 - ignore_case ?
786 - strihash(translated->pattern) :
787 - strhash(translated->pattern));
785 + fspathhash(translated->pattern));
786
787 if (!hashmap_get_entry(&pl->recursive_hashmap,
788 translated, ent, NULL)) {
@@ -813,9 +811,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
811 translated->pattern = dup_and_filter_pattern(given->pattern);
812 translated->patternlen = given->patternlen;
813 hashmap_entry_init(&translated->ent,
816 - ignore_case ?
817 - strihash(translated->pattern) :
818 - strhash(translated->pattern));
814 + fspathhash(translated->pattern));
815
816 hashmap_add(&pl->recursive_hashmap, &translated->ent);
817
@@ -845,10 +841,7 @@ static int hashmap_contains_path(struct hashmap *map,
841 /* Check straight mapping */
842 p.pattern = pattern->buf;
843 p.patternlen = pattern->len;
848 - hashmap_entry_init(&p.ent,
849 - ignore_case ?
850 - strihash(p.pattern) :
851 - strhash(p.pattern));
844 + hashmap_entry_init(&p.ent, fspathhash(p.pattern));
845 return !!hashmap_get_entry(map, &p, ent, NULL);
846 }
847
merge-recursive.c
+3 -8
@@ -61,11 +61,6 @@ static int path_hashmap_cmp(const void *cmp_data,
61 return strcmp(a->path, key ? key : b->path);
62 }
63
64 -static unsigned int path_hash(const char *path)
65 -{
66 - return ignore_case ? strihash(path) : strhash(path);
67 -}
68 -
64 /*
65 * For dir_rename_entry, directory names are stored as a full path from the
66 * toplevel of the repository and do not include a trailing '/'. Also:
@@ -463,7 +458,7 @@ static int save_files_dirs(const struct object_id *oid,
458 strbuf_addstr(base, path);
459
460 FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
466 - hashmap_entry_init(&entry->e, path_hash(entry->path));
461 + hashmap_entry_init(&entry->e, fspathhash(entry->path));
462 hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
463
464 strbuf_setlen(base, baselen);
@@ -737,14 +732,14 @@ static char *unique_path(struct merge_options *opt,
732
733 base_len = newpath.len;
734 while (hashmap_get_from_hash(&opt->priv->current_file_dir_set,
740 - path_hash(newpath.buf), newpath.buf) ||
735 + fspathhash(newpath.buf), newpath.buf) ||
736 (!opt->priv->call_depth && file_exists(newpath.buf))) {
737 strbuf_setlen(&newpath, base_len);
738 strbuf_addf(&newpath, "_%d", suffix++);
739 }
740
741 FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
747 - hashmap_entry_init(&entry->e, path_hash(entry->path));
742 + hashmap_entry_init(&entry->e, fspathhash(entry->path));
743 hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
744 return strbuf_detach(&newpath, NULL);
745 }