v7-0008-Casefold-lazily-in-guc_name_compare.patch
text/x-patch
Filename: v7-0008-Casefold-lazily-in-guc_name_compare.patch
Type: text/x-patch
Part: 7
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: format-patch
Series: patch v7-0008
Subject: Casefold lazily in guc_name_compare
| File | + | − |
|---|---|---|
| src/backend/utils/misc/guc.c | 9 | 5 |
From 9be7bb1212e390b356e3310c3e29e6eda7f56e59 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Sat, 9 Dec 2023 17:30:39 +0700
Subject: [PATCH v7 08/13] Casefold lazily in guc_name_compare
We can assume that almost all GUC names are lower case,
so compare each byte with strict equality first. If that
fails retry the comparison with down-casing.
TODO: This concept only been tested inlined into simplehash,
so need to see if this makes any difference on its own.
---
src/backend/utils/misc/guc.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 053be81d14..1484e11a42 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -1305,12 +1305,16 @@ guc_name_compare(const char *namea, const char *nameb)
char cha = *namea++;
char chb = *nameb++;
- if (cha >= 'A' && cha <= 'Z')
- cha += 'a' - 'A';
- if (chb >= 'A' && chb <= 'Z')
- chb += 'a' - 'A';
if (cha != chb)
- return cha - chb;
+ {
+ /* Casefold lazily since we expect lower case */
+ if (cha >= 'A' && cha <= 'Z')
+ cha += 'a' - 'A';
+ if (chb >= 'A' && chb <= 'Z')
+ chb += 'a' - 'A';
+ if (cha != chb)
+ return cha - chb;
+ }
}
if (*namea)
return 1; /* a is longer */
--
2.43.0