Skip to content

Instantly share code, notes, and snippets.

@dstogov
Created October 23, 2013 12:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dstogov/7117649 to your computer and use it in GitHub Desktop.
Save dstogov/7117649 to your computer and use it in GitHub Desktop.
Improve get_func_args() performance by eliminating unnecessary zval copying
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);
}
}
@hikari-no-yume
Copy link

Looks like you've accidentally mixed up tabs and spaces at the end, there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment