summaryrefslogtreecommitdiff
path: root/Zend
diff options
context:
space:
mode:
authorMatt Wilmas <mattwil@php.net>2008-05-27 10:29:33 +0000
committerMatt Wilmas <mattwil@php.net>2008-05-27 10:29:33 +0000
commit7da75d81e7993e8c0dd56edf2614be4ce69970a4 (patch)
treed840bb6eaa090116900c27b861eb265c474282aa /Zend
parenta2da2a91b1278c21b73f1ef5c9f6d4500d6b0c45 (diff)
downloadphp-git-7da75d81e7993e8c0dd56edf2614be4ce69970a4.tar.gz
MFH: Add array_init_size() and use it where array size is known at initialization
Diffstat (limited to 'Zend')
-rw-r--r--Zend/zend_API.c4
-rw-r--r--Zend/zend_API.h5
-rw-r--r--Zend/zend_builtin_functions.c12
-rw-r--r--Zend/zend_object_handlers.c4
4 files changed, 12 insertions, 13 deletions
diff --git a/Zend/zend_API.c b/Zend/zend_API.c
index a3b2b1e4ae..163ec5411c 100644
--- a/Zend/zend_API.c
+++ b/Zend/zend_API.c
@@ -922,11 +922,11 @@ ZEND_API int zend_parse_method_parameters_ex(int flags, int num_args TSRMLS_DC,
/* }}} */
/* Argument parsing API -- andrei */
-ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC) /* {{{ */
+ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC) /* {{{ */
{
ALLOC_HASHTABLE_REL(Z_ARRVAL_P(arg));
- _zend_hash_init(Z_ARRVAL_P(arg), 0, NULL, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC);
+ _zend_hash_init(Z_ARRVAL_P(arg), size, NULL, ZVAL_PTR_DTOR, 0 ZEND_FILE_LINE_RELAY_CC);
Z_TYPE_P(arg) = IS_ARRAY;
return SUCCESS;
}
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index a71900f514..19be6f08a5 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -316,11 +316,12 @@ ZEND_API char *zend_get_type_by_const(int type);
#define DLEXPORT
#endif
-#define array_init(arg) _array_init((arg) ZEND_FILE_LINE_CC)
+#define array_init(arg) _array_init((arg), 0 ZEND_FILE_LINE_CC)
+#define array_init_size(arg, size) _array_init((arg), (size) ZEND_FILE_LINE_CC)
#define object_init(arg) _object_init((arg) ZEND_FILE_LINE_CC TSRMLS_CC)
#define object_init_ex(arg, ce) _object_init_ex((arg), (ce) ZEND_FILE_LINE_CC TSRMLS_CC)
#define object_and_properties_init(arg, ce, properties) _object_and_properties_init((arg), (ce), (properties) ZEND_FILE_LINE_CC TSRMLS_CC)
-ZEND_API int _array_init(zval *arg ZEND_FILE_LINE_DC);
+ZEND_API int _array_init(zval *arg, uint size ZEND_FILE_LINE_DC);
ZEND_API int _object_init(zval *arg ZEND_FILE_LINE_DC TSRMLS_DC);
ZEND_API int _object_init_ex(zval *arg, zend_class_entry *ce ZEND_FILE_LINE_DC TSRMLS_DC);
ZEND_API int _object_and_properties_init(zval *arg, zend_class_entry *ce, HashTable *properties ZEND_FILE_LINE_DC TSRMLS_DC);
diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c
index 9006e15fde..11447bb6a1 100644
--- a/Zend/zend_builtin_functions.c
+++ b/Zend/zend_builtin_functions.c
@@ -285,7 +285,7 @@ ZEND_FUNCTION(func_get_args)
p = ex->function_state.arguments;
arg_count = (int)(zend_uintptr_t) *p; /* this is the amount of arguments passed to func_get_args(); */
- array_init(return_value);
+ array_init_size(return_value, arg_count);
for (i=0; i<arg_count; i++) {
zval *element;
@@ -1526,16 +1526,14 @@ ZEND_FUNCTION(get_defined_functions)
Returns an associative array of names and values of all currently defined variable names (variables in the current scope) */
ZEND_FUNCTION(get_defined_vars)
{
- zval *tmp;
-
- array_init(return_value);
-
if (!EG(active_symbol_table)) {
zend_rebuild_symbol_table(TSRMLS_C);
}
+ array_init_size(return_value, zend_hash_num_elements(EG(active_symbol_table)));
+
zend_hash_copy(Z_ARRVAL_P(return_value), EG(active_symbol_table),
- (copy_ctor_func_t)zval_add_ref, &tmp, sizeof(zval *));
+ (copy_ctor_func_t)zval_add_ref, NULL, sizeof(zval *));
}
/* }}} */
@@ -1764,7 +1762,7 @@ static zval *debug_backtrace_get_args(void **curpos TSRMLS_DC)
int arg_count = (int)(zend_uintptr_t) *p;
MAKE_STD_ZVAL(arg_array);
- array_init(arg_array);
+ array_init_size(arg_array, arg_count);
p -= arg_count;
while (--arg_count >= 0) {
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 20a465dca3..71f843b339 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -654,7 +654,7 @@ ZEND_API void zend_std_call_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{ */
ALLOC_ZVAL(method_args_ptr);
INIT_PZVAL(method_args_ptr);
- array_init(method_args_ptr);
+ array_init_size(method_args_ptr, ZEND_NUM_ARGS());
if (zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE) {
zval_dtor(method_args_ptr);
@@ -853,7 +853,7 @@ ZEND_API void zend_std_callstatic_user_call(INTERNAL_FUNCTION_PARAMETERS) /* {{{
ALLOC_ZVAL(method_args_ptr);
INIT_PZVAL(method_args_ptr);
- array_init(method_args_ptr);
+ array_init_size(method_args_ptr, ZEND_NUM_ARGS());
if (zend_copy_parameters_array(ZEND_NUM_ARGS(), method_args_ptr TSRMLS_CC) == FAILURE) {
zval_dtor(method_args_ptr);