Skip to content

Commit 433d8f4

Browse files
committed
Remove separate locale_is_c arguments
Since e9931bf, ctype_is_c is part of pg_locale_t. Some functions passed a pg_locale_t and a bool argument separately. This can now be combined into one argument. Since some callers call MatchText() with locale 0, it is a bit confusing whether this is all correct. But it is the case that only callers that pass a non-zero locale object to MatchText() end up checking locale->ctype_is_c. To make that flow a bit more understandable, add the locale argument to MATCH_LOWER() and GETCHAR() in like_match.c, instead of implicitly taking it from the outer scope. Reviewed-by: Jeff Davis <pgsql@j-davis.com> Discussion: https://www.postgresql.org/message-id/84d415fc-6780-419e-b16c-61a0ca819e2b@eisentraut.org
1 parent 2b67bdc commit 433d8f4

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

src/backend/utils/adt/like.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@
3333

3434

3535
static int SB_MatchText(const char *t, int tlen, const char *p, int plen,
36-
pg_locale_t locale, bool locale_is_c);
36+
pg_locale_t locale);
3737
static text *SB_do_like_escape(text *pat, text *esc);
3838

3939
static int MB_MatchText(const char *t, int tlen, const char *p, int plen,
40-
pg_locale_t locale, bool locale_is_c);
40+
pg_locale_t locale);
4141
static text *MB_do_like_escape(text *pat, text *esc);
4242

4343
static int UTF8_MatchText(const char *t, int tlen, const char *p, int plen,
44-
pg_locale_t locale, bool locale_is_c);
44+
pg_locale_t locale);
4545

4646
static int SB_IMatchText(const char *t, int tlen, const char *p, int plen,
47-
pg_locale_t locale, bool locale_is_c);
47+
pg_locale_t locale);
4848

4949
static int GenericMatchText(const char *s, int slen, const char *p, int plen, Oid collation);
5050
static int Generic_Text_IC_like(text *str, text *pat, Oid collation);
@@ -91,9 +91,9 @@ wchareq(const char *p1, const char *p2)
9191
* fold-on-the-fly processing, however.
9292
*/
9393
static char
94-
SB_lower_char(unsigned char c, pg_locale_t locale, bool locale_is_c)
94+
SB_lower_char(unsigned char c, pg_locale_t locale)
9595
{
96-
if (locale_is_c)
96+
if (locale->ctype_is_c)
9797
return pg_ascii_tolower(c);
9898
else
9999
return tolower_l(c, locale->info.lt);
@@ -129,7 +129,7 @@ SB_lower_char(unsigned char c, pg_locale_t locale, bool locale_is_c)
129129
#include "like_match.c"
130130

131131
/* setup to compile like_match.c for single byte case insensitive matches */
132-
#define MATCH_LOWER(t) SB_lower_char((unsigned char) (t), locale, locale_is_c)
132+
#define MATCH_LOWER(t, locale) SB_lower_char((unsigned char) (t), locale)
133133
#define NextChar(p, plen) NextByte((p), (plen))
134134
#define MatchText SB_IMatchText
135135

@@ -158,11 +158,11 @@ GenericMatchText(const char *s, int slen, const char *p, int plen, Oid collation
158158
}
159159

160160
if (pg_database_encoding_max_length() == 1)
161-
return SB_MatchText(s, slen, p, plen, 0, true);
161+
return SB_MatchText(s, slen, p, plen, 0);
162162
else if (GetDatabaseEncoding() == PG_UTF8)
163-
return UTF8_MatchText(s, slen, p, plen, 0, true);
163+
return UTF8_MatchText(s, slen, p, plen, 0);
164164
else
165-
return MB_MatchText(s, slen, p, plen, 0, true);
165+
return MB_MatchText(s, slen, p, plen, 0);
166166
}
167167

168168
static inline int
@@ -212,17 +212,17 @@ Generic_Text_IC_like(text *str, text *pat, Oid collation)
212212
s = VARDATA_ANY(str);
213213
slen = VARSIZE_ANY_EXHDR(str);
214214
if (GetDatabaseEncoding() == PG_UTF8)
215-
return UTF8_MatchText(s, slen, p, plen, 0, true);
215+
return UTF8_MatchText(s, slen, p, plen, 0);
216216
else
217-
return MB_MatchText(s, slen, p, plen, 0, true);
217+
return MB_MatchText(s, slen, p, plen, 0);
218218
}
219219
else
220220
{
221221
p = VARDATA_ANY(pat);
222222
plen = VARSIZE_ANY_EXHDR(pat);
223223
s = VARDATA_ANY(str);
224224
slen = VARSIZE_ANY_EXHDR(str);
225-
return SB_IMatchText(s, slen, p, plen, locale, locale->ctype_is_c);
225+
return SB_IMatchText(s, slen, p, plen, locale);
226226
}
227227
}
228228

@@ -330,7 +330,7 @@ bytealike(PG_FUNCTION_ARGS)
330330
p = VARDATA_ANY(pat);
331331
plen = VARSIZE_ANY_EXHDR(pat);
332332

333-
result = (SB_MatchText(s, slen, p, plen, 0, true) == LIKE_TRUE);
333+
result = (SB_MatchText(s, slen, p, plen, 0) == LIKE_TRUE);
334334

335335
PG_RETURN_BOOL(result);
336336
}
@@ -351,7 +351,7 @@ byteanlike(PG_FUNCTION_ARGS)
351351
p = VARDATA_ANY(pat);
352352
plen = VARSIZE_ANY_EXHDR(pat);
353353

354-
result = (SB_MatchText(s, slen, p, plen, 0, true) != LIKE_TRUE);
354+
result = (SB_MatchText(s, slen, p, plen, 0) != LIKE_TRUE);
355355

356356
PG_RETURN_BOOL(result);
357357
}

src/backend/utils/adt/like_match.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,13 @@
7171
*/
7272

7373
#ifdef MATCH_LOWER
74-
#define GETCHAR(t) MATCH_LOWER(t)
74+
#define GETCHAR(t, locale) MATCH_LOWER(t, locale)
7575
#else
76-
#define GETCHAR(t) (t)
76+
#define GETCHAR(t, locale) (t)
7777
#endif
7878

7979
static int
80-
MatchText(const char *t, int tlen, const char *p, int plen,
81-
pg_locale_t locale, bool locale_is_c)
80+
MatchText(const char *t, int tlen, const char *p, int plen, pg_locale_t locale)
8281
{
8382
/* Fast path for match-everything pattern */
8483
if (plen == 1 && *p == '%')
@@ -106,7 +105,7 @@ MatchText(const char *t, int tlen, const char *p, int plen,
106105
ereport(ERROR,
107106
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
108107
errmsg("LIKE pattern must not end with escape character")));
109-
if (GETCHAR(*p) != GETCHAR(*t))
108+
if (GETCHAR(*p, locale) != GETCHAR(*t, locale))
110109
return LIKE_FALSE;
111110
}
112111
else if (*p == '%')
@@ -166,17 +165,16 @@ MatchText(const char *t, int tlen, const char *p, int plen,
166165
ereport(ERROR,
167166
(errcode(ERRCODE_INVALID_ESCAPE_SEQUENCE),
168167
errmsg("LIKE pattern must not end with escape character")));
169-
firstpat = GETCHAR(p[1]);
168+
firstpat = GETCHAR(p[1], locale);
170169
}
171170
else
172-
firstpat = GETCHAR(*p);
171+
firstpat = GETCHAR(*p, locale);
173172

174173
while (tlen > 0)
175174
{
176-
if (GETCHAR(*t) == firstpat)
175+
if (GETCHAR(*t, locale) == firstpat)
177176
{
178-
int matched = MatchText(t, tlen, p, plen,
179-
locale, locale_is_c);
177+
int matched = MatchText(t, tlen, p, plen, locale);
180178

181179
if (matched != LIKE_FALSE)
182180
return matched; /* TRUE or ABORT */
@@ -198,7 +196,7 @@ MatchText(const char *t, int tlen, const char *p, int plen,
198196
NextByte(p, plen);
199197
continue;
200198
}
201-
else if (GETCHAR(*p) != GETCHAR(*t))
199+
else if (GETCHAR(*p, locale) != GETCHAR(*t, locale))
202200
{
203201
/* non-wildcard pattern char fails to match text char */
204202
return LIKE_FALSE;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy