summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2006-06-11 21:55:49 +0000
committerIlia Alshanetsky <iliaa@php.net>2006-06-11 21:55:49 +0000
commitd74f9ff5506c7f120b3158c960ce62f91308b389 (patch)
treecf75f95fabd7f8cbef1a33ef001b743e8dd36d1e
parent66141bd5d1973d65d47d0580b32724942aea1bfc (diff)
downloadphp-git-d74f9ff5506c7f120b3158c960ce62f91308b389.tar.gz
Improved performance of the implode() function on associated arrays by
200-300%.
-rw-r--r--NEWS2
-rw-r--r--ext/standard/string.c23
2 files changed, 21 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index 4135c94e4f..ff017bf50c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? 2006, PHP 5.2.0
+- Improved performance of the implode() function on associated arrays by
+ 200-300%. (Ilia)
- Improved performance of str_replace() when doing 1 char to 1 char or 1 char
to many chars replacement by 30-40%. (Ilia)
- Added memory_get_peak_usage() function for retrieving peak memory usage of
diff --git a/ext/standard/string.c b/ext/standard/string.c
index a3707bad21..e28b7c1419 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -894,11 +894,23 @@ PHPAPI void php_implode(zval *delim, zval *arr, zval *return_value)
while (zend_hash_get_current_data_ex(Z_ARRVAL_P(arr), (void **) &tmp, &pos) == SUCCESS) {
if ((*tmp)->type != IS_STRING) {
- SEPARATE_ZVAL(tmp);
- convert_to_string(*tmp);
+ if ((*tmp)->type == IS_OBJECT) {
+ int copy;
+ zval expr;
+ zend_make_printable_zval(*tmp, &expr, &copy);
+ smart_str_appendl(&implstr, Z_STRVAL(expr), Z_STRLEN(expr));
+ if (copy) {
+ zval_dtor(&expr);
+ }
+ goto next;
+ } else {
+ SEPARATE_ZVAL(tmp);
+ convert_to_string(*tmp);
+ }
}
smart_str_appendl(&implstr, Z_STRVAL_PP(tmp), Z_STRLEN_PP(tmp));
+next:
if (++i != numelems) {
smart_str_appendl(&implstr, Z_STRVAL_P(delim), Z_STRLEN_P(delim));
}
@@ -916,6 +928,7 @@ PHP_FUNCTION(implode)
{
zval **arg1 = NULL, **arg2 = NULL, *delim, *arr;
int argc = ZEND_NUM_ARGS();
+ HashPosition pos;
if (argc < 1 || argc > 2 ||
zend_get_parameters_ex(argc, &arg1, &arg2) == FAILURE) {
@@ -936,12 +949,10 @@ PHP_FUNCTION(implode)
arr = *arg1;
} else {
if (Z_TYPE_PP(arg1) == IS_ARRAY) {
- SEPARATE_ZVAL(arg1);
arr = *arg1;
convert_to_string_ex(arg2);
delim = *arg2;
} else if (Z_TYPE_PP(arg2) == IS_ARRAY) {
- SEPARATE_ZVAL(arg2);
arr = *arg2;
convert_to_string_ex(arg1);
delim = *arg1;
@@ -951,8 +962,12 @@ PHP_FUNCTION(implode)
}
}
+ pos = Z_ARRVAL_P(arr)->pInternalPointer;
+
php_implode(delim, arr, return_value);
+ Z_ARRVAL_P(arr)->pInternalPointer = pos;
+
if (argc == 1) {
FREE_ZVAL(delim);
}