mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Avoid unnecessary reference-counting on strings.
This commit is contained in:
parent
ce18738a30
commit
ccc12b82da
29 changed files with 636 additions and 510 deletions
|
@ -1415,8 +1415,12 @@ static zend_string *preg_do_repl_func(zend_fcall_info *fci, zend_fcall_info_cach
|
|||
fci->no_separation = 0;
|
||||
|
||||
if (zend_call_function(fci, fcc) == SUCCESS && Z_TYPE(retval) != IS_UNDEF) {
|
||||
result_str = zval_get_string(&retval);
|
||||
zval_ptr_dtor(&retval);
|
||||
if (EXPECTED(Z_TYPE(retval) == IS_STRING)) {
|
||||
result_str = Z_STR(retval);
|
||||
} else {
|
||||
result_str = zval_get_string_func(&retval);
|
||||
zval_ptr_dtor(&retval);
|
||||
}
|
||||
} else {
|
||||
if (!EG(exception)) {
|
||||
php_error_docref(NULL, E_WARNING, "Unable to call custom replacement function");
|
||||
|
@ -1933,7 +1937,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, zval *replace, zend
|
|||
{
|
||||
zval *regex_entry;
|
||||
zend_string *result;
|
||||
zend_string *replace_str;
|
||||
zend_string *replace_str, *tmp_replace_str;
|
||||
|
||||
if (Z_TYPE_P(replace) == IS_ARRAY) {
|
||||
uint32_t replace_idx = 0;
|
||||
|
@ -1942,19 +1946,21 @@ static zend_string *php_pcre_replace_array(HashTable *regex, zval *replace, zend
|
|||
/* For each entry in the regex array, get the entry */
|
||||
ZEND_HASH_FOREACH_VAL(regex, regex_entry) {
|
||||
/* Make sure we're dealing with strings. */
|
||||
zend_string *regex_str = zval_get_string(regex_entry);
|
||||
zend_string *tmp_regex_str;
|
||||
zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str);
|
||||
zval *zv;
|
||||
|
||||
/* Get current entry */
|
||||
while (1) {
|
||||
if (replace_idx == replace_ht->nNumUsed) {
|
||||
replace_str = ZSTR_EMPTY_ALLOC();
|
||||
tmp_replace_str = NULL;
|
||||
break;
|
||||
}
|
||||
zv = &replace_ht->arData[replace_idx].val;
|
||||
replace_idx++;
|
||||
if (Z_TYPE_P(zv) != IS_UNDEF) {
|
||||
replace_str = zval_get_string(zv);
|
||||
replace_str = zval_get_tmp_string(zv, &tmp_replace_str);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1968,8 +1974,8 @@ static zend_string *php_pcre_replace_array(HashTable *regex, zval *replace, zend
|
|||
replace_str,
|
||||
limit,
|
||||
replace_count);
|
||||
zend_string_release(replace_str);
|
||||
zend_string_release(regex_str);
|
||||
zend_tmp_string_release(tmp_replace_str);
|
||||
zend_tmp_string_release(tmp_regex_str);
|
||||
zend_string_release(subject_str);
|
||||
subject_str = result;
|
||||
if (UNEXPECTED(result == NULL)) {
|
||||
|
@ -1983,7 +1989,8 @@ static zend_string *php_pcre_replace_array(HashTable *regex, zval *replace, zend
|
|||
/* For each entry in the regex array, get the entry */
|
||||
ZEND_HASH_FOREACH_VAL(regex, regex_entry) {
|
||||
/* Make sure we're dealing with strings. */
|
||||
zend_string *regex_str = zval_get_string(regex_entry);
|
||||
zend_string *tmp_regex_str;
|
||||
zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str);
|
||||
|
||||
/* Do the actual replacement and put the result back into subject_str
|
||||
for further replacements. */
|
||||
|
@ -1994,7 +2001,7 @@ static zend_string *php_pcre_replace_array(HashTable *regex, zval *replace, zend
|
|||
replace_str,
|
||||
limit,
|
||||
replace_count);
|
||||
zend_string_release(regex_str);
|
||||
zend_tmp_string_release(tmp_regex_str);
|
||||
zend_string_release(subject_str);
|
||||
subject_str = result;
|
||||
|
||||
|
@ -2057,7 +2064,8 @@ static zend_string *php_replace_in_subject_func(zval *regex, zend_fcall_info *fc
|
|||
/* For each entry in the regex array, get the entry */
|
||||
ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(regex), regex_entry) {
|
||||
/* Make sure we're dealing with strings. */
|
||||
zend_string *regex_str = zval_get_string(regex_entry);
|
||||
zend_string *tmp_regex_str;
|
||||
zend_string *regex_str = zval_get_tmp_string(regex_entry, &tmp_regex_str);
|
||||
|
||||
/* Do the actual replacement and put the result back into subject_str
|
||||
for further replacements. */
|
||||
|
@ -2066,7 +2074,7 @@ static zend_string *php_replace_in_subject_func(zval *regex, zend_fcall_info *fc
|
|||
fci, fcc,
|
||||
limit,
|
||||
replace_count);
|
||||
zend_string_release(regex_str);
|
||||
zend_tmp_string_release(tmp_regex_str);
|
||||
zend_string_release(subject_str);
|
||||
subject_str = result;
|
||||
if (UNEXPECTED(result == NULL)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue