From d46686dcf6c32f2bac05f5cb1ebba4bf19f9b139 Mon Sep 17 00:00:00 2001 From: "Chao Li (Evan)" Date: Thu, 19 Nov 2026 14:24:39 +0800 Subject: [PATCH v1] Avoid rescanning prefixes in appendStringLiteralDQ() When a dollar-quote delimiter candidate occurs in the input, extend it and resume searching at the previous match. Since each candidate extends the preceding one, it cannot match before that position. This avoids repeatedly scanning prefixes already ruled out. Author: Chao Li --- src/fe_utils/string_utils.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/fe_utils/string_utils.c b/src/fe_utils/string_utils.c index 78ffe6c890a..e3dff73759f 100644 --- a/src/fe_utils/string_utils.c +++ b/src/fe_utils/string_utils.c @@ -487,6 +487,7 @@ appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix) static const char suffixes[] = "_XXXXXXX"; int nextchar = 0; PQExpBuffer delimBuf = createPQExpBuffer(); + const char *searchPtr = str; /* start with $ + dqprefix if not NULL */ appendPQExpBufferChar(delimBuf, '$'); @@ -498,7 +499,7 @@ appendStringLiteralDQ(PQExpBuffer buf, const char *str, const char *dqprefix) * present in the string being quoted. We don't check with the trailing $ * because a string ending in $foo must not be quoted with $foo$. */ - while (strstr(str, delimBuf->data) != NULL) + while ((searchPtr = strstr(searchPtr, delimBuf->data)) != NULL) { appendPQExpBufferChar(delimBuf, suffixes[nextchar++]); nextchar %= sizeof(suffixes) - 1; -- 2.50.1 (Apple Git-155)