Skip to content

Commit 0db7c67

Browse files
committed
Minor code beautification in regexp.c.
Remove duplicated code (apparently introduced by commit c8ea87e). 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
1 parent 1281a5c commit 0db7c67

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/backend/utils/adt/regexp.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct regexp_matches_ctx
6363
Datum *elems; /* has npatterns elements */
6464
bool *nulls; /* has npatterns elements */
6565
pg_wchar *wide_str; /* wide-char version of original string */
66-
char *conv_buf; /* conversion buffer */
66+
char *conv_buf; /* conversion buffer, if needed */
6767
int conv_bufsiz; /* size thereof */
6868
} regexp_matches_ctx;
6969

@@ -1285,7 +1285,6 @@ static ArrayType *
12851285
build_regexp_match_result(regexp_matches_ctx *matchctx)
12861286
{
12871287
char *buf = matchctx->conv_buf;
1288-
int bufsiz PG_USED_FOR_ASSERTS_ONLY = matchctx->conv_bufsiz;
12891288
Datum *elems = matchctx->elems;
12901289
bool *nulls = matchctx->nulls;
12911290
int dims[1];
@@ -1311,7 +1310,7 @@ build_regexp_match_result(regexp_matches_ctx *matchctx)
13111310
buf,
13121311
eo - so);
13131312

1314-
Assert(len < bufsiz);
1313+
Assert(len < matchctx->conv_bufsiz);
13151314
elems[i] = PointerGetDatum(cstring_to_text_with_len(buf, len));
13161315
nulls[i] = false;
13171316
}
@@ -1467,25 +1466,22 @@ build_regexp_split_result(regexp_matches_ctx *splitctx)
14671466
if (startpos < 0)
14681467
elog(ERROR, "invalid match ending position");
14691468

1469+
endpos = splitctx->match_locs[splitctx->next_match * 2];
1470+
if (endpos < startpos)
1471+
elog(ERROR, "invalid match starting position");
1472+
14701473
if (buf)
14711474
{
1472-
int bufsiz PG_USED_FOR_ASSERTS_ONLY = splitctx->conv_bufsiz;
14731475
int len;
14741476

1475-
endpos = splitctx->match_locs[splitctx->next_match * 2];
1476-
if (endpos < startpos)
1477-
elog(ERROR, "invalid match starting position");
14781477
len = pg_wchar2mb_with_len(splitctx->wide_str + startpos,
14791478
buf,
14801479
endpos - startpos);
1481-
Assert(len < bufsiz);
1480+
Assert(len < splitctx->conv_bufsiz);
14821481
return PointerGetDatum(cstring_to_text_with_len(buf, len));
14831482
}
14841483
else
14851484
{
1486-
endpos = splitctx->match_locs[splitctx->next_match * 2];
1487-
if (endpos < startpos)
1488-
elog(ERROR, "invalid match starting position");
14891485
return DirectFunctionCall3(text_substr,
14901486
PointerGetDatum(splitctx->orig_str),
14911487
Int32GetDatum(startpos + 1),

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