Skip to content

Commit

Permalink
GH-96 Replace usage of MapTable by ObjectCache to Dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
Dima Zen committed May 19, 2017
1 parent da552c9 commit f642313
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions FastEasyMapping/Source/Cache/FEMObjectCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
};

@implementation FEMObjectCache {
NSMapTable<FEMMapping *, NSMutableDictionary<id, id> *> *_lookupObjectsMap;
NSMutableDictionary<NSNumber *, NSMutableDictionary<id, id> *> *_lookupObjectsMap;
FEMObjectCacheSource _source;
}

Expand All @@ -22,9 +22,7 @@ - (instancetype)initWithSource:(FEMObjectCacheSource)source {
self = [super init];
if (self) {
_source = source ?: FEMObjectCacheSourceStub;

NSPointerFunctionsOptions options = NSPointerFunctionsObjectPointerPersonality | NSPointerFunctionsStrongMemory;
_lookupObjectsMap = [[NSMapTable alloc] initWithKeyOptions:options valueOptions:options capacity:0];
_lookupObjectsMap = [[NSMutableDictionary alloc] init];
}

return self;
Expand All @@ -47,10 +45,10 @@ - (NSMutableDictionary *)fetchExistingObjectsForMapping:(FEMMapping *)mapping {
}

- (NSMutableDictionary *)cachedObjectsForMapping:(FEMMapping *)mapping {
NSMutableDictionary *entityObjectsMap = [_lookupObjectsMap objectForKey:mapping];
NSMutableDictionary *entityObjectsMap = _lookupObjectsMap[mapping.uniqueIdentifier];
if (!entityObjectsMap) {
entityObjectsMap = [self fetchExistingObjectsForMapping:mapping];
[_lookupObjectsMap setObject:entityObjectsMap forKey:mapping];
_lookupObjectsMap[mapping.uniqueIdentifier] = entityObjectsMap;
}

return entityObjectsMap;
Expand Down

0 comments on commit f642313

Please sign in to comment.