From 0db7c67051806f28a9129d50695efc19372d3af2 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 16 Jan 2020 11:31:30 -0500 Subject: [PATCH] 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 --- src/backend/utils/adt/regexp.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/backend/utils/adt/regexp.c b/src/backend/utils/adt/regexp.c index 2094d50d81..6c76e89c9a 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),