Refactor Vector collection capacity.
commit7979c6f29c6ef71b25d2d8263b8c866bc486c001
authorAlexey Toptygin <alexeyt@fb.com>
Fri, 19 May 2017 20:14:12 +0000 (19 13:14 -0700)
committerHhvm Bot <hhvm-bot@users.noreply.github.com>
Fri, 19 May 2017 20:17:43 +0000 (19 13:17 -0700)
tree6538c043c7220221aa2f6dd64fb5d13c14360754
parent2e42b2af54e7043b6aeabe5beb1b29bcd6121e5f
Refactor Vector collection capacity.

Summary:
Stop tracking capacity in the Vector as well as in the underlying ArrayData. We still track m_size in both, but that's used from the jit and is a refactor for another day.
BaseVector::canMutateBuffer would return true if m_arr was the static empty vec. This is hard to reason about and unnecessary, stop doing it.
Don't req::make empty vectors and then call reserve on them; we already have a constructor that pre-allocates, use that. After this, all the remaining callers of reserve need to increment m_version, so just have reserve do it.
Make mutate and reserve always result in a mutable m_arr; then there's no need to assert that it's mutable after calling them, since they already assert it.
Don't implement our own grow method; all the places that were using it could just use existing PackedArray helpers; use those instead.
Don't update m_size in loops where we can avoid it; do it once before the loop.
Add missing unit tests so that we have coverage of all the code touched.

Reviewed By: edwinsmith

Differential Revision: D4985325

fbshipit-source-id: fe006a2e0648d4bca1cb7f18360a4f89323e22e5
32 files changed:
hphp/runtime/base/collections.cpp
hphp/runtime/base/variable-unserializer.cpp
hphp/runtime/ext/collections/ext_collections-vector.cpp
hphp/runtime/ext/collections/ext_collections-vector.h
hphp/test/slow/collection_classes/concat.php
hphp/test/slow/collection_classes/concat.php.expect
hphp/test/slow/collection_classes/concat_empty.php [new file with mode: 0644]
hphp/test/slow/collection_classes/concat_empty.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/fromKeysOf.php
hphp/test/slow/collection_classes/fromKeysOf.php.expect
hphp/test/slow/collection_classes/keys.php [new file with mode: 0644]
hphp/test/slow/collection_classes/keys.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/skip.php [new file with mode: 0644]
hphp/test/slow/collection_classes/skip.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/skipwhile.php [new file with mode: 0644]
hphp/test/slow/collection_classes/skipwhile.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/take.php [new file with mode: 0644]
hphp/test/slow/collection_classes/take.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/vector-add-vs-immutable.php [new file with mode: 0644]
hphp/test/slow/collection_classes/vector-add-vs-immutable.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/vector-unshift-vs-immutable.php [new file with mode: 0644]
hphp/test/slow/collection_classes/vector-unshift-vs-immutable.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_from_array.php [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_from_array.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_map_empty.php [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_map_empty.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_reserve_vs_immutable.php [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_reserve_vs_immutable.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_resize.php [new file with mode: 0644]
hphp/test/slow/collection_classes/vector_resize.php.expect [new file with mode: 0644]
hphp/test/slow/collection_classes/zip.php [new file with mode: 0644]
hphp/test/slow/collection_classes/zip.php.expect [new file with mode: 0644]