All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] use fspathhash() everywhere
@ 2021-07-30 19:06 René Scharfe
  2021-07-30 19:27 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: René Scharfe @ 2021-07-30 19:06 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano, Eric Wong

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>
---
 builtin/sparse-checkout.c | 10 ++--------
 dir.c                     | 13 +++----------
 merge-recursive.c         | 11 +++--------
 3 files changed, 8 insertions(+), 26 deletions(-)

diff --git a/builtin/sparse-checkout.c b/builtin/sparse-checkout.c
index a4bdd7c494..8ba9f13787 100644
--- a/builtin/sparse-checkout.c
+++ b/builtin/sparse-checkout.c
@@ -380,10 +380,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
 	struct pattern_entry *e = xmalloc(sizeof(*e));
 	e->patternlen = path->len;
 	e->pattern = strbuf_detach(path, NULL);
-	hashmap_entry_init(&e->ent,
-			   ignore_case ?
-			   strihash(e->pattern) :
-			   strhash(e->pattern));
+	hashmap_entry_init(&e->ent, fspathhash(e->pattern));

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

@@ -399,10 +396,7 @@ static void insert_recursive_pattern(struct pattern_list *pl, struct strbuf *pat
 		e = xmalloc(sizeof(struct pattern_entry));
 		e->patternlen = newlen;
 		e->pattern = xstrndup(oldpattern, newlen);
-		hashmap_entry_init(&e->ent,
-				   ignore_case ?
-				   strihash(e->pattern) :
-				   strhash(e->pattern));
+		hashmap_entry_init(&e->ent, fspathhash(e->pattern));

 		if (!hashmap_get_entry(&pl->parent_hashmap, e, ent, NULL))
 			hashmap_add(&pl->parent_hashmap, &e->ent);
diff --git a/dir.c b/dir.c
index 23b4417268..03c4d21267 100644
--- a/dir.c
+++ b/dir.c
@@ -782,9 +782,7 @@ static void add_pattern_to_hashsets(struct pattern_list *pl, struct path_pattern
 		translated->pattern = truncated;
 		translated->patternlen = given->patternlen - 2;
 		hashmap_entry_init(&translated->ent,
-				   ignore_case ?
-				   strihash(translated->pattern) :
-				   strhash(translated->pattern));
+				   fspathhash(translated->pattern));

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

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

@@ -845,10 +841,7 @@ static int hashmap_contains_path(struct hashmap *map,
 	/* Check straight mapping */
 	p.pattern = pattern->buf;
 	p.patternlen = pattern->len;
-	hashmap_entry_init(&p.ent,
-			   ignore_case ?
-			   strihash(p.pattern) :
-			   strhash(p.pattern));
+	hashmap_entry_init(&p.ent, fspathhash(p.pattern));
 	return !!hashmap_get_entry(map, &p, ent, NULL);
 }

diff --git a/merge-recursive.c b/merge-recursive.c
index 7008a90df5..3355d50e8a 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -61,11 +61,6 @@ static int path_hashmap_cmp(const void *cmp_data,
 		return strcmp(a->path, key ? key : b->path);
 }

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

 	FLEX_ALLOC_MEM(entry, path, base->buf, base->len);
-	hashmap_entry_init(&entry->e, path_hash(entry->path));
+	hashmap_entry_init(&entry->e, fspathhash(entry->path));
 	hashmap_add(&opt->priv->current_file_dir_set, &entry->e);

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

 	base_len = newpath.len;
 	while (hashmap_get_from_hash(&opt->priv->current_file_dir_set,
-				     path_hash(newpath.buf), newpath.buf) ||
+				     fspathhash(newpath.buf), newpath.buf) ||
 	       (!opt->priv->call_depth && file_exists(newpath.buf))) {
 		strbuf_setlen(&newpath, base_len);
 		strbuf_addf(&newpath, "_%d", suffix++);
 	}

 	FLEX_ALLOC_MEM(entry, path, newpath.buf, newpath.len);
-	hashmap_entry_init(&entry->e, path_hash(entry->path));
+	hashmap_entry_init(&entry->e, fspathhash(entry->path));
 	hashmap_add(&opt->priv->current_file_dir_set, &entry->e);
 	return strbuf_detach(&newpath, NULL);
 }
--
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] use fspathhash() everywhere
  2021-07-30 19:06 [PATCH] use fspathhash() everywhere René Scharfe
@ 2021-07-30 19:27 ` Junio C Hamano
  2021-07-30 20:22   ` René Scharfe
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2021-07-30 19:27 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git List, Eric Wong

René Scharfe <l.s.r@web.de> writes:

> 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>
> ---
>  builtin/sparse-checkout.c | 10 ++--------
>  dir.c                     | 13 +++----------
>  merge-recursive.c         | 11 +++--------
>  3 files changed, 8 insertions(+), 26 deletions(-)

I love this kind of "now we have this thing available, let's use it
at more places" clean-up patch.

Was coccinelle involved in finding these places?

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] use fspathhash() everywhere
  2021-07-30 19:27 ` Junio C Hamano
@ 2021-07-30 20:22   ` René Scharfe
  0 siblings, 0 replies; 3+ messages in thread
From: René Scharfe @ 2021-07-30 20:22 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Git List, Eric Wong

Am 30.07.21 um 21:27 schrieb Junio C Hamano:
> René Scharfe <l.s.r@web.de> writes:
>
>> 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>
>> ---
>>  builtin/sparse-checkout.c | 10 ++--------
>>  dir.c                     | 13 +++----------
>>  merge-recursive.c         | 11 +++--------
>>  3 files changed, 8 insertions(+), 26 deletions(-)
>
> I love this kind of "now we have this thing available, let's use it
> at more places" clean-up patch.
>
> Was coccinelle involved in finding these places?

Just git grep this time; there were not enough hits for me to consider
writing a semantic patch.

René

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-07-30 20:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 19:06 [PATCH] use fspathhash() everywhere René Scharfe
2021-07-30 19:27 ` Junio C Hamano
2021-07-30 20:22   ` René Scharfe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.