threads / patch / 58585

patchdir: use fspathncmp() in pl_hashmap_cmp()

Subject: [PATCH] dir: use fspathncmp() in pl_hashmap_cmp()

## tl;dr

2 messages between Oct 8, 2022 and Oct 11, 2022. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

René Scharfe· Oct 8, 2022, 11:05 UTC · lore
From: Jeff King <peff@peff.net>

Call fspathncmp() instead of open-coding it. This shortens the code and makes it less repetitive.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
From https://lore.kernel.org/git/YSv1XZJvYdYj1JtP@coredump.intra.peff.net/
 dir.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Show changes to dir.c +1 −4
diff --git a/dir.c b/dir.c
index 7d56d68355..28f4c6895b 100644
--- a/dir.c
+++ b/dir.c
@@ -669,9 +669,7 @@ int pl_hashmap_cmp(const void *cmp_data UNUSED,
 			 ? ee1->patternlen
 			 : ee2->patternlen;

-	if (ignore_case)
-		return strncasecmp(ee1->pattern, ee2->pattern, min_len);
-	return strncmp(ee1->pattern, ee2->pattern, min_len);
+	return fspathncmp(ee1->pattern, ee2->pattern, min_len);
 }

 static char *dup_and_filter_pattern(const char *pattern)
--
2.38.0
Jeff King· Oct 11, 2022, 00:19 UTC · re: René Scharfe · lore

Re: [PATCH] dir: use fspathncmp() in pl_hashmap_cmp()

On Sat, Oct 08, 2022 at 01:05:43PM +0200, René Scharfe wrote:
Show 8 quoted lines
> From: Jeff King <peff@peff.net>
> 
> Call fspathncmp() instead of open-coding it.  This shortens the code and
> makes it less repetitive.
> 
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> From https://lore.kernel.org/git/YSv1XZJvYdYj1JtP@coredump.intra.peff.net/
That's an old one. :) Thanks for hanging on to it.
Show 13 quoted lines
> diff --git a/dir.c b/dir.c
> index 7d56d68355..28f4c6895b 100644
> --- a/dir.c
> +++ b/dir.c
> @@ -669,9 +669,7 @@ int pl_hashmap_cmp(const void *cmp_data UNUSED,
>  			 ? ee1->patternlen
>  			 : ee2->patternlen;
> 
> -	if (ignore_case)
> -		return strncasecmp(ee1->pattern, ee2->pattern, min_len);
> -	return strncmp(ee1->pattern, ee2->pattern, min_len);
> +	return fspathncmp(ee1->pattern, ee2->pattern, min_len);
>  }

Unlike the other one discussed in that thread, where there is a shadow ignore_case, we decided that this one is a true simplification.

-Peff

← back to recent threads