Created
October 23, 2013 12:23
-
-
Save dstogov/7117649 to your computer and use it in GitHub Desktop.
Improve get_func_args() performance by eliminating unnecessary zval copying
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c | |
index 1ad64e7..6cbe0bc 100644 | |
--- a/Zend/zend_builtin_functions.c | |
+++ b/Zend/zend_builtin_functions.c | |
@@ -461,12 +461,17 @@ ZEND_FUNCTION(func_get_args) | |
array_init_size(return_value, arg_count); | |
for (i=0; i<arg_count; i++) { | |
- zval *element; | |
+ zval *element, *arg; | |
- ALLOC_ZVAL(element); | |
- *element = **((zval **) (p-(arg_count-i))); | |
- zval_copy_ctor(element); | |
- INIT_PZVAL(element); | |
+ arg = *((zval **) (p-(arg_count-i))); | |
+ if (!Z_ISREF_P(arg)) { | |
+ element = arg; | |
+ Z_ADDREF_P(element); | |
+ } else { | |
+ ALLOC_ZVAL(element); | |
+ INIT_PZVAL_COPY(element, arg); | |
+ zval_copy_ctor(element); | |
+ } | |
zend_hash_next_index_insert(return_value->value.ht, &element, sizeof(zval *), NULL); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like you've accidentally mixed up tabs and spaces at the end, there.