summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2022-10-06 15:18:32 +0000
committerTom Lane2022-10-06 15:18:32 +0000
commit58640f37d9acf632a4dd60d140f36f2e6815f716 (patch)
treec37eeaa21a221e717bef931dec2724a560b7247f
parentca71131eebba63809ceb86be033a264a5f0a1d79 (diff)
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/[email protected]
-rw-r--r--contrib/ltree/lquery_op.c9
-rw-r--r--contrib/ltree/ltree.h2
-rw-r--r--contrib/ltree/ltxtquery_io.c16
3 files changed, 13 insertions, 14 deletions
diff --git a/contrib/ltree/lquery_op.c b/contrib/ltree/lquery_op.c
index d5803392836..a6466f575fd 100644
--- a/contrib/ltree/lquery_op.c
+++ b/contrib/ltree/lquery_op.c
@@ -25,17 +25,16 @@ static char *
getlexeme(char *start, char *end, int *len)
{
char *ptr;
- int charlen;
- while (start < end && (charlen = pg_mblen(start)) == 1 && t_iseq(start, '_'))
- start += charlen;
+ while (start < end && t_iseq(start, '_'))
+ start += pg_mblen(start);
ptr = start;
if (ptr >= end)
return NULL;
- while (ptr < end && !((charlen = pg_mblen(ptr)) == 1 && t_iseq(ptr, '_')))
- ptr += charlen;
+ while (ptr < end && !t_iseq(ptr, '_'))
+ ptr += pg_mblen(ptr);
*len = ptr - start;
return start;
diff --git a/contrib/ltree/ltree.h b/contrib/ltree/ltree.h
index 6939d7349a1..2a80a02495e 100644
--- a/contrib/ltree/ltree.h
+++ b/contrib/ltree/ltree.h
@@ -126,7 +126,7 @@ typedef struct
#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 */
diff --git a/contrib/ltree/ltxtquery_io.c b/contrib/ltree/ltxtquery_io.c
index 3eca5cb8ff3..8ab0ce8e52b 100644
--- a/contrib/ltree/ltxtquery_io.c
+++ b/contrib/ltree/ltxtquery_io.c
@@ -64,13 +64,13 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
switch (state->state)
{
case WAITOPERAND:
- if (charlen == 1 && t_iseq(state->buf, '!'))
+ if (t_iseq(state->buf, '!'))
{
(state->buf)++;
*val = (int32) '!';
return OPR;
}
- else if (charlen == 1 && t_iseq(state->buf, '('))
+ else if (t_iseq(state->buf, '('))
{
state->count++;
(state->buf)++;
@@ -97,11 +97,11 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
errmsg("modifiers syntax error")));
*lenval += charlen;
}
- else if (charlen == 1 && t_iseq(state->buf, '%'))
+ else if (t_iseq(state->buf, '%'))
*flag |= LVAR_SUBLEXEME;
- else if (charlen == 1 && t_iseq(state->buf, '@'))
+ else if (t_iseq(state->buf, '@'))
*flag |= LVAR_INCASE;
- else if (charlen == 1 && t_iseq(state->buf, '*'))
+ else if (t_iseq(state->buf, '*'))
*flag |= LVAR_ANYEND;
else
{
@@ -110,14 +110,14 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
}
break;
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;
*val = (int32) *(state->buf);
(state->buf)++;
return OPR;
}
- else if (charlen == 1 && t_iseq(state->buf, ')'))
+ else if (t_iseq(state->buf, ')'))
{
(state->buf)++;
state->count--;
@@ -125,7 +125,7 @@ gettoken_query(QPRS_STATE *state, int32 *val, int32 *lenval, char **strval, uint
}
else if (*(state->buf) == '\0')
return (state->count) ? ERR : END;
- else if (charlen == 1 && !t_iseq(state->buf, ' '))
+ else if (!t_iseq(state->buf, ' '))
return ERR;
break;
default: