Hey:
On Wed, Jul 27, 2016 at 10:42 PM, Benjamin Coutu <[email protected]>
wrote:
> 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.
>
I think it's a good idea,
one suggestion is you should check HASH_FLAG_PACKED first, as
!perserve_keys is most common.
and maybe you should use Z_TRY_ADDREF instead of zval_add_ref, check
REFCOUNTED in place, to save one function call if it's not TYPE_REFCOUNTED.
btw, do you want to make a PR yourself, or let me to commit your idea?
thanks
>
> Thanks,
>
> Ben
>
> --
>
> Bejamin Coutu
> [email protected]
>
> ZeyOS, Inc.
> http://www.zeyos.com
>
>
--
Xinchen Hui
@Laruence
http://www.laruence.com/