diff --git a/hphp/runtime/ext/thrift/binary.cpp b/hphp/runtime/ext/thrift/binary.cpp index 9a1e0bbcb66e6..d86b17500dceb 100644 --- a/hphp/runtime/ext/thrift/binary.cpp +++ b/hphp/runtime/ext/thrift/binary.cpp @@ -176,7 +176,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, auto const& val_spec = fieldspec.val(); hasTypeWrapper = hasTypeWrapper || val_spec.isTypeWrapped; if (s_harray.equal(fieldspec.format)) { - DictInit arr(get_initial_array_size(size)); + DictInit arr(size); for (uint32_t i = 0; i < size; i++) { switch (types[0]) { case TType::T_I08: @@ -208,7 +208,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, } return arr.toVariant(); } else if (s_collection.equal(fieldspec.format)) { - auto obj(req::make(get_initial_array_size(size))); + auto obj(req::make(size)); for (uint32_t s = 0; s < size; ++s) { auto key = binary_deserialize( types[0], transport, key_spec, options, hasTypeWrapper); @@ -218,7 +218,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, } return Variant(std::move(obj)); } else { - DictInit arr(get_initial_array_size(size)); + DictInit arr(size); if (options & k_THRIFT_MARK_LEGACY_ARRAYS) { arr.setLegacyArray(); } @@ -250,7 +250,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, if (size == 0) { return Variant(req::make()); } - auto vec = req::make(get_initial_array_size(size)); + auto vec = req::make(size); int64_t i = 0; do { auto val = binary_deserialize( @@ -280,7 +280,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, check_container_size(size); auto const& val_spec = fieldspec.val(); if (s_harray.equal(fieldspec.format)) { - KeysetInit arr(get_initial_array_size(size)); + KeysetInit arr(size); for (uint32_t i = 0; i < size; i++) { arr.add( binary_deserialize(type, transport, val_spec, options, hasTypeWrapper) @@ -288,7 +288,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, } return arr.toVariant(); } else if (s_collection.equal(fieldspec.format)) { - auto set_ret(req::make(get_initial_array_size(size))); + auto set_ret(req::make(size)); for (uint32_t s = 0; s < size; ++s) { Variant key = binary_deserialize( type, transport, val_spec, options, hasTypeWrapper); @@ -301,7 +301,7 @@ Variant binary_deserialize_internal(int8_t thrift_typeID, return Variant(std::move(set_ret)); } else { - DictInit init(get_initial_array_size(size)); + DictInit init(size); if (options & k_THRIFT_MARK_LEGACY_ARRAYS) { init.setLegacyArray(); } diff --git a/hphp/runtime/ext/thrift/compact.cpp b/hphp/runtime/ext/thrift/compact.cpp index 2f54cabbea1ef..91c9e4b448d09 100644 --- a/hphp/runtime/ext/thrift/compact.cpp +++ b/hphp/runtime/ext/thrift/compact.cpp @@ -1118,7 +1118,7 @@ struct CompactReader { const uint32_t size, bool& hasTypeWrapper ) { - DictInit arr(get_initial_array_size(size)); + DictInit arr(size); switch (keyType) { case TType::T_I08: case TType::T_I16: @@ -1163,7 +1163,7 @@ struct CompactReader { const uint32_t size, bool& hasTypeWrapper ) { - auto map(req::make(get_initial_array_size(size))); + auto map(req::make(size)); if (spec.key().adapter == nullptr && spec.val().adapter == nullptr && typeIs16to64Int(keyType) && typeIs16to64Int(valueType)) { hasTypeWrapper = hasTypeWrapper || spec.key().isTypeWrapped || spec.val().isTypeWrapped; @@ -1190,7 +1190,7 @@ struct CompactReader { } else if (s_collection.equal(spec.format)) { return readMapCollection(spec, keyType, valueType, size, hasTypeWrapper); } else { - DictInit arr(get_initial_array_size(size)); + DictInit arr(size); if (options & k_THRIFT_MARK_LEGACY_ARRAYS) { arr.setLegacyArray(); } @@ -1260,7 +1260,7 @@ struct CompactReader { readCollectionEnd(); return Variant(req::make()); } - auto vec = req::make(get_initial_array_size(size)); + auto vec = req::make(size); if (spec.val().adapter == nullptr && typeIs16to64Int(valueType)) { readIntList( [&, i = 0LL](int64_t val) mutable { @@ -1307,14 +1307,14 @@ struct CompactReader { readListBegin(valueType, size); if (s_harray.equal(spec.format)) { - KeysetInit arr(get_initial_array_size(size)); + KeysetInit arr(size); for (uint32_t i = 0; i < size; i++) { arr.add(readField(spec.val(), valueType, hasTypeWrapper)); } readCollectionEnd(); return arr.toVariant(); } else if (s_collection.equal(spec.format)) { - auto set_ret = req::make(get_initial_array_size(size)); + auto set_ret = req::make(size); for (uint32_t i = 0; i < size; i++) { Variant value = readField(spec.val(), valueType, hasTypeWrapper); set_ret->add(value); @@ -1322,7 +1322,7 @@ struct CompactReader { readCollectionEnd(); return Variant(std::move(set_ret)); } else { - DictInit ainit(get_initial_array_size(size)); + DictInit ainit(size); if (options & k_THRIFT_MARK_LEGACY_ARRAYS) { ainit.setLegacyArray(); } diff --git a/hphp/runtime/ext/thrift/util.h b/hphp/runtime/ext/thrift/util.h index 370eda797f08e..85d2cc53af55a 100644 --- a/hphp/runtime/ext/thrift/util.h +++ b/hphp/runtime/ext/thrift/util.h @@ -79,15 +79,11 @@ inline bool is_value_type_default(int8_t thrift_typeID, const Variant& value) { } } -inline uint32_t get_initial_array_size(const uint32_t size) { +inline Array initialize_array(const uint32_t size) { // Reserve up to 16k entries for perf - but after that use "normal" // array expansion so that we ensure the data is actually there before // allocating massive arrays. - return std::min(16384u, size); -} - -inline Array initialize_array(const uint32_t size) { - return Array::attach(VanillaVec::MakeReserveVec(get_initial_array_size(size))); + return Array::attach(VanillaVec::MakeReserveVec(std::min(16384u, size))); } inline void check_container_size(const uint32_t size) {