Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Minor code beautification in regexp.c.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Jan 2020 16:31:30 +0000 (11:31 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 16 Jan 2020 16:31:30 +0000 (11:31 -0500)
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

index 2094d50d810c276c2fb0530c4eae8169cab24e3d..6c76e89c9aefab438856193aeaa6fe2e2933948d 100644 (file)
@@ -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),