Skip to content

Commit 71daef9

Browse files
committed
preg_replace() optimization
1 parent 5f05527 commit 71daef9

File tree

5 files changed

+582
-262
lines changed

5 files changed

+582
-262
lines changed

ext/fileinfo/libmagic/funcs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
471471
int opts = 0;
472472
pcre_cache_entry *pce;
473473
zend_string *res;
474-
zval repl;
474+
zend_string *repl;
475475
int rep_cnt = 0;
476476

477477
(void)setlocale(LC_CTYPE, "C");
@@ -485,10 +485,10 @@ file_replace(struct magic_set *ms, const char *pat, const char *rep)
485485
}
486486
zval_ptr_dtor(&patt);
487487

488-
ZVAL_STRING(&repl, rep);
489-
res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), &repl, 0, -1, &rep_cnt);
488+
repl = zend_string_init(rep, strlen(rep), 0);
489+
res = php_pcre_replace_impl(pce, NULL, ms->o.buf, strlen(ms->o.buf), repl, -1, &rep_cnt);
490490

491-
zval_ptr_dtor(&repl);
491+
zend_string_release(repl);
492492
if (NULL == res) {
493493
rep_cnt = -1;
494494
goto out;

0 commit comments

Comments
 (0)