mirror of
https://github.com/scandum/tintin
synced 2026-08-13 20:23:04 -04:00
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:
commit
199fa58050
2 changed files with 9 additions and 6 deletions
10
src/regex.c
10
src/regex.c
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue