From: Dmitry Stogov Date: Wed, 3 Sep 2014 14:21:36 +0000 (+0400) Subject: Preallocate hash tables of required size X-Git-Tag: PRE_PHP7_REMOVALS~130 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c897aa7dab65c1aa5b9197086b3a610f0428fd0;p=php Preallocate hash tables of required size --- diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c index 1f50ad462a..f320585e70 100644 --- a/Zend/zend_builtin_functions.c +++ b/Zend/zend_builtin_functions.c @@ -1062,7 +1062,7 @@ ZEND_FUNCTION(get_object_vars) zobj = Z_OBJ_P(obj); - array_init(return_value); + array_init_size(return_value, zend_hash_num_elements(properties)); ZEND_HASH_FOREACH_STR_KEY_VAL_IND(properties, key, value) { if (key) { diff --git a/Zend/zend_objects.c b/Zend/zend_objects.c index 9eea73deaf..40d37b3d36 100644 --- a/Zend/zend_objects.c +++ b/Zend/zend_objects.c @@ -154,7 +154,7 @@ ZEND_API void zend_objects_clone_members(zend_object *new_object, zend_object *o if (!new_object->properties) { ALLOC_HASHTABLE(new_object->properties); - zend_hash_init(new_object->properties, 8, NULL, ZVAL_PTR_DTOR, 0); + zend_hash_init(new_object->properties, zend_hash_num_elements(old_object->properties), NULL, ZVAL_PTR_DTOR, 0); } ZEND_HASH_FOREACH_KEY_VAL(old_object->properties, num_key, key, prop) { diff --git a/ext/opcache/Optimizer/compact_literals.c b/ext/opcache/Optimizer/compact_literals.c index 78f1d28445..28e7a11314 100644 --- a/ext/opcache/Optimizer/compact_literals.c +++ b/ext/opcache/Optimizer/compact_literals.c @@ -311,7 +311,7 @@ void zend_optimizer_compact_literals(zend_op_array *op_array, zend_optimizer_ctx /* Merge equal constants */ j = 0; cache_slots = 0; - zend_hash_init(&hash, 16, NULL, NULL, 0); + zend_hash_init(&hash, op_array->last_literal, NULL, NULL, 0); map = (int*)zend_arena_alloc(&ctx->arena, op_array->last_literal * sizeof(int)); memset(map, 0, op_array->last_literal * sizeof(int)); for (i = 0; i < op_array->last_literal; i++) {