Merge pull request #277 from jaypatrickhoward/claude_perf_fixes

Two small hot-path performance fixes (regex match_data reuse, vt102 strip)
This commit is contained in:
Igor van den Hoven 2026-08-06 21:54:02 +02:00 committed by GitHub
commit 199fa58050
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 6 deletions

View file

@ -108,7 +108,12 @@ int regexp_compare(struct session *ses, pcre2_code *nodepcre, char *str, char *e
return FALSE;
}
pcre2_match_data *match_data = pcre2_match_data_create(101, NULL);
static pcre2_match_data *match_data = NULL;
if (match_data == NULL)
{
match_data = pcre2_match_data_create(101, NULL);
}
matches = pcre2_match(regex, (PCRE2_SPTR) str, strlen(str), 0, 0, match_data, NULL);
@ -118,7 +123,6 @@ int regexp_compare(struct session *ses, pcre2_code *nodepcre, char *str, char *e
{
pcre2_code_free(regex);
}
pcre2_match_data_free(match_data);
return FALSE;
}
@ -127,8 +131,6 @@ int regexp_compare(struct session *ses, pcre2_code *nodepcre, char *str, char *e
memcpy(gtd->match, ovector, matches * 2 * sizeof(PCRE2_SIZE));
pcre2_match_data_free(match_data);
// REGEX_FLAG_FIX handles %1 to %99 usage. Backward compatible.
switch (flag)

View file

@ -586,15 +586,16 @@ int find_secure_color_code(char *str)
int strip_vt102_codes(char *str, char *buf)
{
char *pti, *pto;
int skip;
pti = (char *) str;
pto = (char *) buf;
while (*pti)
{
while (skip_vt102_codes(pti))
while ((skip = skip_vt102_codes(pti)))
{
pti += skip_vt102_codes(pti);
pti += skip;
}
if (*pti)