GetPosKey should not inc-ref
commitc723c30e5135ffaa1f3ac29967e6dd93ffb77e8b
authorShaunak Kishore <kshaunak@fb.com>
Fri, 3 Apr 2020 05:19:21 +0000 (2 22:19 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Fri, 3 Apr 2020 05:41:49 +0000 (2 22:41 -0700)
treec5fef4b33abc88bbd60872cfd31394cf8969e79e
parentc2cb633837da93edfa2976dc689c80c2a490184d
GetPosKey should not inc-ref

Summary:
For consistency with GetPosVal, and just in general as a value-returning function, GetPosKey should not inc-ref the result.

I audited all callers of MixedArray::getKey, nvGetKey, and nvFirst to see if they were using the extra refcount and changed those that were to do a Variant::attach or similar. Most callers weren't making use of the extra refcount - for these callers, this change will fix a small leak to the GC.

There's only one place here where perf might matter: for the ArrayIter helpers, doing the inc-ref in MixedArrayElm might be faster... However, I think if GCC's analysis is good enough, we should get the same code (because we test the DataType and we set it to constants in the three branches - Int, String, and PersistentString). If this place ends up mattering I'll just add a getKeyIncRef to MixedArrayElm.

This diff is a lot smaller than the previous one, but also more delicate, hence splitting it out.

Reviewed By: ricklavoie

Differential Revision: D20820640

fbshipit-source-id: ae0055df8c972525ea9498d5241bad9cea41166c
hphp/runtime/base/apc-local-array.cpp
hphp/runtime/base/array-data-defs.h
hphp/runtime/base/array-data.cpp
hphp/runtime/base/array-iterator.cpp
hphp/runtime/base/mixed-array.h
hphp/runtime/base/set-array.cpp
hphp/runtime/base/set-array.h
hphp/runtime/vm/globals-array.cpp