Skip to contentSkip to conversation

dir: use fspathncmp() in pl_hashmap_cmp()

PATCH In review René Scharfe 2 participants 2 messages Oct 8, 2022 – Oct 11, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dir: use fspathncmp() in pl_hashmap_cmp()

From: Jeff King <[email protected]>

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

---
From https://lore.kernel.org/git/[email protected]/

 dir.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
dir.c +1 -3
index 7d56d68355..28f4c6895b 100644
@@ -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

#1 lore raw
Quoted 8 lines · René Scharfe

From: Jeff King <[email protected]>

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

---
From https://lore.kernel.org/git/[email protected]/

That's an old one. :) Thanks for hanging on to it.

dir.c int pl_hashmap_cmp(const void *cmp_data UNUSED, · line 673

Quoted 13 lines
dir.c +1 -3
index 7d56d68355..28f4c6895b 100644
@@ -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