diff --git a/valdi_core/src/valdi_core/ios/valdi_core/SCValdiObjCConversionUtils.mm b/valdi_core/src/valdi_core/ios/valdi_core/SCValdiObjCConversionUtils.mm index c73157bf..d0660d5f 100644 --- a/valdi_core/src/valdi_core/ios/valdi_core/SCValdiObjCConversionUtils.mm +++ b/valdi_core/src/valdi_core/ios/valdi_core/SCValdiObjCConversionUtils.mm @@ -219,8 +219,9 @@ id NSObjectFromValue(const Valdi::Value &value) { return @(value.toBool()); case Valdi::ValueType::Map: { - NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - for (const auto &it : *value.getMap()) { + const auto &valueMap = *value.getMap(); + NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:valueMap.size()]; + for (const auto &it : valueMap) { dictionary[NSStringFromString(it.first)] = NSObjectFromValue(it.second); } @@ -244,7 +245,7 @@ id NSObjectFromValue(const Valdi::Value &value) { case Valdi::ValueType::TypedObject: { const auto &typedObject = *value.getTypedObject(); - NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; + NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithCapacity:typedObject.getPropertiesSize()]; for (const auto &property: typedObject) { dictionary[NSStringFromString(property.name)] = NSObjectFromValue(property.value); } @@ -348,6 +349,7 @@ id NSObjectFromValue(const Valdi::Value &value) { Valdi::Value ValueFromNSDictionary(NSDictionary *dict) { auto map = Valdi::makeShared(); + map->reserve(dict.count); for (NSString *key in dict) { id value = [dict objectForKey:key]; auto weakValue = ValueFromNSObject(value);