summaryrefslogtreecommitdiff
path: root/ext/pcre/php_pcre.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-04-02 01:56:16 +0400
committerDmitry Stogov <dmitry@zend.com>2014-04-02 01:56:16 +0400
commit7240b4ec4d31d61abcc97c315a826cfaf91ce188 (patch)
tree980727b91a3fc0e932952086aeb339b0de32508e /ext/pcre/php_pcre.c
parent5c912a805b9f4342a2353142620b248ea24b5dca (diff)
downloadphp-git-7240b4ec4d31d61abcc97c315a826cfaf91ce188.tar.gz
Avoid unnecessary zval separations
Diffstat (limited to 'ext/pcre/php_pcre.c')
-rw-r--r--ext/pcre/php_pcre.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c
index da691287b9..eb77a39cb3 100644
--- a/ext/pcre/php_pcre.c
+++ b/ext/pcre/php_pcre.c
@@ -1226,14 +1226,20 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub
zval *regex_entry,
*replace_entry = NULL,
*replace_value,
+ tmp_subject,
empty_replace;
zend_string *subject_value;
zend_string *result;
- /* Make sure we're dealing with strings. */
+ /* Make sure we're dealing with strings. */
+ if (Z_ISREF_P(subject)) {
+ subject = Z_REFVAL_P(subject);
+ }
+ ZVAL_UNDEF(&tmp_subject);
if (Z_TYPE_P(subject) != IS_STRING) {
- SEPARATE_ZVAL(subject);
- convert_to_string_ex(subject);
+ ZVAL_DUP(&tmp_subject, subject);
+ convert_to_string_ex(&tmp_subject);
+ subject = &tmp_subject;
}
/* FIXME: This might need to be changed to STR_EMPTY_ALLOC(). Check if this zval could be dtor()'ed somehow */
@@ -1284,12 +1290,14 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub
subject_value = result;
} else {
STR_RELEASE(subject_value);
+ zval_ptr_dtor(&tmp_subject);
return NULL;
}
zend_hash_move_forward(Z_ARRVAL_P(regex));
}
+ zval_ptr_dtor(&tmp_subject);
return subject_value;
} else {
result = php_pcre_replace(Z_STR_P(regex),
@@ -1299,6 +1307,7 @@ static zend_string *php_replace_in_subject(zval *regex, zval *replace, zval *sub
is_callable_replace,
limit,
replace_count TSRMLS_CC);
+ zval_ptr_dtor(&tmp_subject);
return result;
}
}