Skip to content

Commit

Permalink
chore: RCTConvert - allocate array with capacity (facebook#35490)
Browse files Browse the repository at this point in the history
Summary:
this is a trivial change that allocates the NSMutableArray with the correct capacity before it is filled

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Internal] [Changed] - RCTConvertVecToArray - allocate array with capacity

Pull Request resolved: facebook#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
  • Loading branch information
vonovak authored and facebook-github-bot committed Nov 28, 2022
1 parent 6c6dbf6 commit e325c95
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Libraries/TypeSafety/RCTConvertHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using LazyVector = FB::LazyVector<T, id>;
template <typename ContainerT>
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;
Expand Down

0 comments on commit e325c95

Please sign in to comment.