Skip to content

Commit 58640f3

Browse files
committed
Remove useless character-length checks in contrib/ltree.
The t_iseq() macro does not need to be guarded by a character length check (at least when the comparison value is an ASCII character, as its documentation requires). Some portions of contrib/ltree hadn't read that memo, so simplify them. The last change in gettoken_query, - else if (charlen == 1 && !t_iseq(state->buf, ' ')) + else if (!t_iseq(state->buf, ' ')) looks like it's actually a bug fix: I doubt that the intention was to silently ignore multibyte characters as if they were whitespace. I'm not tempted to back-patch though, because this will have the effect of tightening what is allowed in ltxtquery strings. Discussion: https://postgr.es/m/2548310.1664999615@sss.pgh.pa.us
1 parent ca71131 commit 58640f3

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

contrib/ltree/lquery_op.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ static char *
2525
getlexeme(char *start, char *end, int *len)
2626
{
2727
char *ptr;
28-
int charlen;
2928

30-
while (start < end && (charlen = pg_mblen(start)) == 1 && t_iseq(start, '_'))
31-
start += charlen;
29+
while (start < end && t_iseq(start, '_'))
30+
start += pg_mblen(start);
3231

3332
ptr = start;
3433
if (ptr >= end)
3534
return NULL;
3635

37-
while (ptr < end && !((charlen = pg_mblen(ptr)) == 1 && t_iseq(ptr, '_')))
38-
ptr += charlen;
36+
while (ptr < end && !t_iseq(ptr, '_'))
37+
ptr += pg_mblen(ptr);
3938

4039
*len = ptr - start;
4140
return start;

contrib/ltree/ltree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ typedef struct
126126

127127
#define LQUERY_HASNOT 0x01
128128

129-
#define ISALNUM(x) ( t_isalnum(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) )
129+
#define ISALNUM(x) ( t_isalnum(x) || t_iseq(x, '_') )
130130

131131
/* full text query */
132132

contrib/ltree/ltxtquery_io.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
6464
switch (state->state)
6565
{
6666
case WAITOPERAND:
67-
if (charlen == 1 && t_iseq(state->buf, '!'))
67+
if (t_iseq(state->buf, '!'))
6868
{
6969
(state->buf)++;
7070
*val = (int32) '!';
7171
return OPR;
7272
}
73-
else if (charlen == 1 && t_iseq(state->buf, '('))
73+
else if (t_iseq(state->buf, '('))
7474
{
7575
state->count++;
7676
(state->buf)++;
@@ -97,11 +97,11 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
9797
errmsg("modifiers syntax error")));
9898
*lenval += charlen;
9999
}
100-
else if (charlen == 1 && t_iseq(state->buf, '%'))
100+
else if (t_iseq(state->buf, '%'))
101101
*flag |= LVAR_SUBLEXEME;
102-
else if (charlen == 1 && t_iseq(state->buf, '@'))
102+
else if (t_iseq(state->buf, '@'))
103103
*flag |= LVAR_INCASE;
104-
else if (charlen == 1 && t_iseq(state->buf, '*'))
104+
else if (t_iseq(state->buf, '*'))
105105
*flag |= LVAR_ANYEND;
106106
else
107107
{
@@ -110,22 +110,22 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
110110
}
111111
break;
112112
case WAITOPERATOR:
113-
if (charlen == 1 && (t_iseq(state->buf, '&') || t_iseq(state->buf, '|')))
113+
if (t_iseq(state->buf, '&') || t_iseq(state->buf, '|'))
114114
{
115115
state->state = WAITOPERAND;
116116
*val = (int32) *(state->buf);
117117
(state->buf)++;
118118
return OPR;
119119
}
120-
else if (charlen == 1 && t_iseq(state->buf, ')'))
120+
else if (t_iseq(state->buf, ')'))
121121
{
122122
(state->buf)++;
123123
state->count--;
124124
return (state->count < 0) ? ERR : CLOSE;
125125
}
126126
else if (*(state->buf) == '\0')
127127
return (state->count) ? ERR : END;
128-
else if (charlen == 1 && !t_iseq(state->buf, ' '))
128+
else if (!t_iseq(state->buf, ' '))
129129
return ERR;
130130
break;
131131
default:

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