From e325c9505adbd1674ad0828dc50abd6c0280e700 Mon Sep 17 00:00:00 2001 From: Vojtech Novak Date: Mon, 28 Nov 2022 07:29:04 -0800 Subject: [PATCH] chore: RCTConvert - allocate array with capacity (#35490) Summary: this is a trivial change that allocates the NSMutableArray with the correct capacity before it is filled ## Changelog [Internal] [Changed] - RCTConvertVecToArray - allocate array with capacity Pull Request resolved: https://github.com/facebook/react-native/pull/35490 Test Plan: tested locally: the code builds and runs as expected Reviewed By: cipolleschi Differential Revision: D41548050 Pulled By: GijsWeterings fbshipit-source-id: a5b947331d6c5fffcfecc7c20c827f42442b1ab8 --- Libraries/TypeSafety/RCTConvertHelpers.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/TypeSafety/RCTConvertHelpers.h b/Libraries/TypeSafety/RCTConvertHelpers.h index e7bd47bcbd26bf..d33f42c8ff18d8 100644 --- a/Libraries/TypeSafety/RCTConvertHelpers.h +++ b/Libraries/TypeSafety/RCTConvertHelpers.h @@ -23,7 +23,7 @@ using LazyVector = FB::LazyVector; template NSArray *RCTConvertVecToArray(const ContainerT &vec, id (^convertor)(typename ContainerT::value_type element)) { - NSMutableArray *array = [NSMutableArray new]; + NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:vec.size()]; for (size_t i = 0, size = vec.size(); i < size; ++i) { id object = convertor(vec[i]); array[i] = object ?: (id)kCFNull;