3 ms·
10-20x slower means it makes sense to use a persistent map when the size of your Dictionary is > 20 records. Then, // yourDictionary is NSMutableDictionary,
by astashov 12y ago
10-20x slower means it makes sense to use a persistent map when the size of your Dictionary is > 20 records.
Then,
// yourDictionary is NSMutableDictionary, [yourDictionary count] > 20
NSMutableDictionary *mutable = [yourDictionary mutableCopy];
mutable[@"old_key"] = @"new_value";
NSDictionary *changedDict = [NSDictionary dictionaryWithDictionary:mutable];
will be slower than
// yourDictionary is AAPersistentHashMap, [yourDictionary count] > 20
AAPersistentHashMap *changedDict = [yourDictionary setObject:@"new_value" forKey:@"old_key"];
Remember, you need to get another immutable map, which is a modified version of the original, preferably memory-efficient, which means we want to reuse the unchanged keys/values of the original map.