diff options
author | Dmitry Stogov <dmitry@zend.com> | 2017-05-30 10:02:04 +0300 |
---|---|---|
committer | Dmitry Stogov <dmitry@zend.com> | 2017-05-30 10:02:04 +0300 |
commit | c45e3632a2fc1e20d3c60476504f84b057bfc600 (patch) | |
tree | bddf876dc04c879a41a8f2c0807fb3f77bd48ea5 /ext/pcre/php_pcre.c | |
parent | 37a16a32c97fba3e5528aa4a3a675431f3cae136 (diff) | |
download | php-git-c45e3632a2fc1e20d3c60476504f84b057bfc600.tar.gz |
Don't allocate empty strings, use single interned string instead.
Diffstat (limited to 'ext/pcre/php_pcre.c')
-rw-r--r-- | ext/pcre/php_pcre.c | 66 |
1 files changed, 49 insertions, 17 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index c7d6507d77..8fb45a3b41 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -648,8 +648,12 @@ static inline void add_offset_pair(zval *result, char *str, int len, int offset, array_init_size(&match_pair, 2); /* Add (match, offset) to the return value */ - if (unmatched_as_null && offset < 0) { - ZVAL_NULL(&tmp); + if (offset < 0) { + if (unmatched_as_null) { + ZVAL_NULL(&tmp); + } else { + ZVAL_EMPTY_STRING(&tmp); + } } else { ZVAL_STRINGL(&tmp, str, len); } @@ -856,8 +860,12 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec } } else { for (i = 0; i < count; i++) { - if (unmatched_as_null && offsets[i<<1] < 0) { - add_next_index_null(&match_sets[i]); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_next_index_null(&match_sets[i]); + } else { + add_next_index_str(&match_sets[i], ZSTR_EMPTY_ALLOC()); + } } else { add_next_index_stringl(&match_sets[i], (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); @@ -881,7 +889,7 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec if (unmatched_as_null) { add_next_index_null(&match_sets[i]); } else { - add_next_index_string(&match_sets[i], ""); + add_next_index_str(&match_sets[i], ZSTR_EMPTY_ALLOC()); } } } @@ -899,15 +907,23 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec } else { for (i = 0; i < count; i++) { if (subpat_names[i]) { - if (unmatched_as_null && offsets[i<<1] < 0) { - add_assoc_null(&result_set, subpat_names[i]); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_assoc_null(&result_set, subpat_names[i]); + } else { + add_assoc_str(&result_set, subpat_names[i], ZSTR_EMPTY_ALLOC()); + } } else { add_assoc_stringl(&result_set, subpat_names[i], (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); } } - if (unmatched_as_null && offsets[i<<1] < 0) { - add_next_index_null(&result_set); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_next_index_null(&result_set); + } else { + add_next_index_str(&result_set, ZSTR_EMPTY_ALLOC()); + } } else { add_next_index_stringl(&result_set, (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); @@ -922,8 +938,12 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec } } else { for (i = 0; i < count; i++) { - if (unmatched_as_null && offsets[i<<1] < 0) { - add_next_index_null(&result_set); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_next_index_null(&result_set); + } else { + add_next_index_str(&result_set, ZSTR_EMPTY_ALLOC()); + } } else { add_next_index_stringl(&result_set, (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); @@ -950,15 +970,23 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec } else { for (i = 0; i < count; i++) { if (subpat_names[i]) { - if (unmatched_as_null && offsets[i<<1] < 0) { - add_assoc_null(subpats, subpat_names[i]); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_assoc_null(subpats, subpat_names[i]); + } else { + add_assoc_str(subpats, subpat_names[i], ZSTR_EMPTY_ALLOC()); + } } else { add_assoc_stringl(subpats, subpat_names[i], (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); } } - if (unmatched_as_null && offsets[i<<1] < 0) { - add_next_index_null(subpats); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_next_index_null(subpats); + } else { + add_next_index_str(subpats, ZSTR_EMPTY_ALLOC()); + } } else { add_next_index_stringl(subpats, (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); @@ -974,8 +1002,12 @@ PHPAPI void php_pcre_match_impl(pcre_cache_entry *pce, char *subject, int subjec } } else { for (i = 0; i < count; i++) { - if (unmatched_as_null && offsets[i<<1] < 0) { - add_next_index_null(subpats); + if (offsets[i<<1] < 0) { + if (unmatched_as_null) { + add_next_index_null(subpats); + } else { + add_next_index_str(subpats, ZSTR_EMPTY_ALLOC()); + } } else { add_next_index_stringl(subpats, (char *)stringlist[i], offsets[(i<<1)+1] - offsets[i<<1]); |