Skip to content

Commit 7431842

Browse files
rscharfegitster
authored andcommitted
use fspathhash() everywhere
cf2dc1c (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 940fe20 commit 7431842

File tree

3 files changed

+8
-26
lines changed

3 files changed

+8
-26
lines changed

builtin/sparse-checkout.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
380380
struct pattern_entry *e = xmalloc(sizeof(*e));
381381
e->patternlen = path->len;
382382
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));
387384

388385
hashmap_add(&pl->recursive_hashmap, &e->ent);
389386

@@ -399,10 +396,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
399396
e = xmalloc(sizeof(struct pattern_entry));
400397
e->patternlen = newlen;
401398
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));
406400

407401
if (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL))
408402
hashmap_add(&pl->parent_hashmap, &e->ent);

dir.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -782,9 +782,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
782782
translated->pattern = truncated;
783783
translated->patternlen = given->patternlen - 2;
784784
hashmap_entry_init(&translated->ent,
785-
ignore_case ?
786-
strihash(translated->pattern) :
787-
strhash(translated->pattern));
785+
fspathhash(translated->pattern));
788786

789787
if (!hashmap_get_entry(&pl->recursive_hashmap,
790788
translated, ent, NULL)) {
@@ -813,9 +811,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
813811
translated->pattern = dup_and_filter_pattern(given->pattern);
814812
translated->patternlen = given->patternlen;
815813
hashmap_entry_init(&translated->ent,
816-
ignore_case ?
817-
strihash(translated->pattern) :
818-
strhash(translated->pattern));
814+
fspathhash(translated->pattern));
819815

820816
hashmap_add(&pl->recursive_hashmap, &translated->ent);
821817

@@ -845,10 +841,7 @@ static int hashmap_contains_path(struct hashmap *map,
845841
/* Check straight mapping */
846842
p.pattern = pattern->buf;
847843
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));
852845
return !!hashmap_get_entry(map, &p, ent, NULL);
853846
}
854847

merge-recursive.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,6 @@ static int path_hashmap_cmp(const void *cmp_data,
6161
return strcmp(a->path, key ? key : b->path);
6262
}
6363

64-
static unsigned int path_hash(const char *path)
65-
{
66-
return ignore_case ? strihash(path) : strhash(path);
67-
}
68-
6964
/*
7065
* For dir_rename_entry, directory names are stored as a full path from the
7166
* 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,
463458
strbuf_addstr(base, path);
464459

465460
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));
467462
hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
468463

469464
strbuf_setlen(base, baselen);
@@ -737,14 +732,14 @@ static char *unique_path(struct merge_options *opt,
737732

738733
base_len = newpath.len;
739734
while (hashmap_get_from_hash(&opt->priv->current_file_dir_set,
740-
path_hash(newpath.buf), newpath.buf) ||
735+
fspathhash(newpath.buf), newpath.buf) ||
741736
(!opt->priv->call_depth && file_exists(newpath.buf))) {
742737
strbuf_setlen(&newpath, base_len);
743738
strbuf_addf(&newpath, "_%d", suffix++);
744739
}
745740

746741
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));
748743
hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
749744
return strbuf_detach(&newpath, NULL);
750745
}

0 commit comments

Comments
 (0)