1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-18 17:42:25 +03:00

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
This commit is contained in:
Tom Lane
2022-10-06 11:18:32 -04:00
parent ca71131eeb
commit 58640f37d9
3 changed files with 13 additions and 14 deletions

View File

@ -25,17 +25,16 @@ static char *
getlexeme(char *start, char *end, int *len) getlexeme(char *start, char *end, int *len)
{ {
char *ptr; char *ptr;
int charlen;
while (start < end && (charlen = pg_mblen(start)) == 1 && t_iseq(start, '_')) while (start < end && t_iseq(start, '_'))
start += charlen; start += pg_mblen(start);
ptr = start; ptr = start;
if (ptr >= end) if (ptr >= end)
return NULL; return NULL;
while (ptr < end && !((charlen = pg_mblen(ptr)) == 1 && t_iseq(ptr, '_'))) while (ptr < end && !t_iseq(ptr, '_'))
ptr += charlen; ptr += pg_mblen(ptr);
*len = ptr - start; *len = ptr - start;
return start; return start;

View File

@ -126,7 +126,7 @@ typedef struct
#define LQUERY_HASNOT 0x01 #define LQUERY_HASNOT 0x01
#define ISALNUM(x) ( t_isalnum(x) || ( pg_mblen(x) == 1 && t_iseq((x), '_') ) ) #define ISALNUM(x) ( t_isalnum(x) || t_iseq(x, '_') )
/* full text query */ /* full text query */

View File

@ -64,13 +64,13 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
switch (state->state) switch (state->state)
{ {
case WAITOPERAND: case WAITOPERAND:
if (charlen == 1 && t_iseq(state->buf, '!')) if (t_iseq(state->buf, '!'))
{ {
(state->buf)++; (state->buf)++;
*val = (int32) '!'; *val = (int32) '!';
return OPR; return OPR;
} }
else if (charlen == 1 && t_iseq(state->buf, '(')) else if (t_iseq(state->buf, '('))
{ {
state->count++; state->count++;
(state->buf)++; (state->buf)++;
@ -97,11 +97,11 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
errmsg("modifiers syntax error"))); errmsg("modifiers syntax error")));
*lenval += charlen; *lenval += charlen;
} }
else if (charlen == 1 && t_iseq(state->buf, '%')) else if (t_iseq(state->buf, '%'))
*flag |= LVAR_SUBLEXEME; *flag |= LVAR_SUBLEXEME;
else if (charlen == 1 && t_iseq(state->buf, '@')) else if (t_iseq(state->buf, '@'))
*flag |= LVAR_INCASE; *flag |= LVAR_INCASE;
else if (charlen == 1 && t_iseq(state->buf, '*')) else if (t_iseq(state->buf, '*'))
*flag |= LVAR_ANYEND; *flag |= LVAR_ANYEND;
else else
{ {
@ -110,14 +110,14 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
} }
break; break;
case WAITOPERATOR: case WAITOPERATOR:
if (charlen == 1 && (t_iseq(state->buf, '&') || t_iseq(state->buf, '|'))) if (t_iseq(state->buf, '&') || t_iseq(state->buf, '|'))
{ {
state->state = WAITOPERAND; state->state = WAITOPERAND;
*val = (int32) *(state->buf); *val = (int32) *(state->buf);
(state->buf)++; (state->buf)++;
return OPR; return OPR;
} }
else if (charlen == 1 && t_iseq(state->buf, ')')) else if (t_iseq(state->buf, ')'))
{ {
(state->buf)++; (state->buf)++;
state->count--; state->count--;
@ -125,7 +125,7 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
} }
else if (*(state->buf) == '\0') else if (*(state->buf) == '\0')
return (state->count) ? ERR : END; return (state->count) ? ERR : END;
else if (charlen == 1 && !t_iseq(state->buf, ' ')) else if (!t_iseq(state->buf, ' '))
return ERR; return ERR;
break; break;
default: default: