Optimizing array_reverse for packed hash ta bles (when preserve_keys=false)

From: Date: Wed, 27 Jul 2016 14:42:00 +0000
Subject: Optimizing array_reverse for packed hash ta bles (when preserve_keys=false)
Groups: php.internals 
Request: Send a blank email to internals+get-94727@lists.php.net to get a copy of this message
Hello Xinchen, Analogue to the array_slice implementation, the array_reverse function could also be optimized for packed hash tables when preserve_keys is false (most common). The following patch should do just that: if (!preserve_keys && (Z_ARRVAL_P(input)->u.flags & HASH_FLAG_PACKED)) { zend_hash_real_init(Z_ARRVAL_P(return_value), 1); ZEND_HASH_FILL_PACKED(Z_ARRVAL_P(return_value)) { ZEND_HASH_REVERSE_FOREACH_VAL(Z_ARRVAL_P(input), entry) { ZEND_HASH_FILL_ADD(entry); zval_add_ref(entry); } ZEND_HASH_FOREACH_END(); } ZEND_HASH_FILL_END(); } Please let me know your thoughts. Thanks, Ben -- Bejamin Coutu ben.coutu@zeyos.com ZeyOS, Inc. http://www.zeyos.com

« previous php.internals (#94727) next »