From b7dab8c30fef13eace9c348defa47a8bd5ccfb95 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 8 Jul 2021 14:34:18 +0800 Subject: [PATCH] iOS: use NSHashTable to store DoricRegistry instead --- doric-iOS/Pod/Classes/DoricRegistry.m | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/doric-iOS/Pod/Classes/DoricRegistry.m b/doric-iOS/Pod/Classes/DoricRegistry.m index b6211d87..2267740c 100644 --- a/doric-iOS/Pod/Classes/DoricRegistry.m +++ b/doric-iOS/Pod/Classes/DoricRegistry.m @@ -57,7 +57,7 @@ @interface DoricLibraries : NSObject @property(nonatomic, strong) NSMutableSet *libraries; -@property(nonatomic, strong) NSMutableArray *registries; +@property(nonatomic, strong) NSHashTable *registries; @property(nonatomic, strong) NSMutableDictionary *envDic; @property(nonatomic, assign) BOOL enablePerformance; @@ -68,7 +68,7 @@ @implementation DoricLibraries - (instancetype)init { if (self = [super init]) { _libraries = [NSMutableSet new]; - _registries = [NSMutableArray new]; + _registries = [NSHashTable new]; _envDic = [NSMutableDictionary new]; _enablePerformance = NO; } @@ -99,8 +99,7 @@ @implementation DoricRegistry + (void)register:(DoricLibrary *)library { [DoricLibraries.instance.libraries addObject:library]; - for (NSValue *value in DoricLibraries.instance.registries) { - DoricRegistry *registry = value.nonretainedObjectValue; + for (DoricRegistry *registry in DoricLibraries.instance.registries) { if (registry) { [library load:registry]; } @@ -109,8 +108,7 @@ + (void)register:(DoricLibrary *)library { + (void)setEnvironmentValue:(NSDictionary *)value { [DoricLibraries.instance.envDic addEntriesFromDictionary:value]; - for (NSValue *val in DoricLibraries.instance.registries) { - DoricRegistry *registry = val.nonretainedObjectValue; + for (DoricRegistry *registry in DoricLibraries.instance.registries) { if (registry) { [registry innerSetEnvironmentValue:value]; } @@ -124,13 +122,12 @@ - (instancetype)initWithJSEngine:(DoricJSEngine *)jsEngine { _plugins = [NSMutableDictionary new]; _nodes = [NSMutableDictionary new]; _monitors = [NSMutableSet new]; - NSValue *value = [NSValue valueWithNonretainedObject:self]; [self innerRegister]; [DoricLibraries.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) { [obj load:self]; }]; [jsEngine setEnvironmentValue:DoricLibraries.instance.envDic]; - [DoricLibraries.instance.registries addObject:value]; + [DoricLibraries.instance.registries addObject:self]; } return self; }