aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/regexp.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-01-16 11:31:30 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2020-01-16 11:31:30 -0500
commit0db7c67051806f28a9129d50695efc19372d3af2 (patch)
tree1187c964882f711e1ca06b4105e19854fe9ed3e0 /src/backend/utils/adt/regexp.c
parent1281a5c907b41e992a66deb13c3aa61888a62268 (diff)
downloadpostgresql-0db7c67051806f28a9129d50695efc19372d3af2.tar.gz
postgresql-0db7c67051806f28a9129d50695efc19372d3af2.zip
Minor code beautification in regexp.c.
Remove duplicated code (apparently introduced by commit c8ea87e4b). Also get rid of some PG_USED_FOR_ASSERTS_ONLY variables we don't really need to have. Li Japin, Tom Lane Discussion: https://postgr.es/m/PS1PR0601MB3770A5595B6E5E3FD6F35724B6360@PS1PR0601MB3770.apcprd06.prod.outlook.com
Diffstat (limited to 'src/backend/utils/adt/regexp.c')
-rw-r--r--src/backend/utils/adt/regexp.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c
index 2094d50d810..6c76e89c9ae 100644
--- a/src/backend/utils/adt/regexp.c
+++ b/src/backend/utils/adt/regexp.c
@@ -63,7 +63,7 @@ typedef struct regexp_matches_ctx
Datum *elems; /* has npatterns elements */
bool *nulls; /* has npatterns elements */
pg_wchar *wide_str; /* wide-char version of original string */
- char *conv_buf; /* conversion buffer */
+ char *conv_buf; /* conversion buffer, if needed */
int conv_bufsiz; /* size thereof */
} regexp_matches_ctx;
@@ -1285,7 +1285,6 @@ static ArrayType *
build_regexp_match_result(regexp_matches_ctx *matchctx)
{
char *buf = matchctx->conv_buf;
- int bufsiz PG_USED_FOR_ASSERTS_ONLY = matchctx->conv_bufsiz;
Datum *elems = matchctx->elems;
bool *nulls = matchctx->nulls;
int dims[1];
@@ -1311,7 +1310,7 @@ build_regexp_match_result(regexp_matches_ctx *matchctx)
buf,
eo - so);
- Assert(len < bufsiz);
+ Assert(len < matchctx->conv_bufsiz);
elems[i] = PointerGetDatum(cstring_to_text_with_len(buf, len));
nulls[i] = false;
}
@@ -1467,25 +1466,22 @@ build_regexp_split_result(regexp_matches_ctx *splitctx)
if (startpos < 0)
elog(ERROR, "invalid match ending position");
+ endpos = splitctx->match_locs[splitctx->next_match * 2];
+ if (endpos < startpos)
+ elog(ERROR, "invalid match starting position");
+
if (buf)
{
- int bufsiz PG_USED_FOR_ASSERTS_ONLY = splitctx->conv_bufsiz;
int len;
- endpos = splitctx->match_locs[splitctx->next_match * 2];
- if (endpos < startpos)
- elog(ERROR, "invalid match starting position");
len = pg_wchar2mb_with_len(splitctx->wide_str + startpos,
buf,
endpos - startpos);
- Assert(len < bufsiz);
+ Assert(len < splitctx->conv_bufsiz);
return PointerGetDatum(cstring_to_text_with_len(buf, len));
}
else
{
- endpos = splitctx->match_locs[splitctx->next_match * 2];
- if (endpos < startpos)
- elog(ERROR, "invalid match starting position");
return DirectFunctionCall3(text_substr,
PointerGetDatum(splitctx->orig_str),
Int32GetDatum(startpos + 1),