iOS: use NSHashTable to store DoricRegistry instead
This commit is contained in:
parent
5c4bbe2fa5
commit
b7dab8c30f
@ -57,7 +57,7 @@
|
|||||||
|
|
||||||
@interface DoricLibraries : NSObject
|
@interface DoricLibraries : NSObject
|
||||||
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
|
@property(nonatomic, strong) NSMutableSet <DoricLibrary *> *libraries;
|
||||||
@property(nonatomic, strong) NSMutableArray <NSValue *> *registries;
|
@property(nonatomic, strong) NSHashTable<DoricRegistry *> *registries;
|
||||||
@property(nonatomic, strong) NSMutableDictionary *envDic;
|
@property(nonatomic, strong) NSMutableDictionary *envDic;
|
||||||
@property(nonatomic, assign) BOOL enablePerformance;
|
@property(nonatomic, assign) BOOL enablePerformance;
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ @implementation DoricLibraries
|
|||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
_libraries = [NSMutableSet new];
|
_libraries = [NSMutableSet new];
|
||||||
_registries = [NSMutableArray new];
|
_registries = [NSHashTable new];
|
||||||
_envDic = [NSMutableDictionary new];
|
_envDic = [NSMutableDictionary new];
|
||||||
_enablePerformance = NO;
|
_enablePerformance = NO;
|
||||||
}
|
}
|
||||||
@ -99,8 +99,7 @@ @implementation DoricRegistry
|
|||||||
|
|
||||||
+ (void)register:(DoricLibrary *)library {
|
+ (void)register:(DoricLibrary *)library {
|
||||||
[DoricLibraries.instance.libraries addObject:library];
|
[DoricLibraries.instance.libraries addObject:library];
|
||||||
for (NSValue *value in DoricLibraries.instance.registries) {
|
for (DoricRegistry *registry in DoricLibraries.instance.registries) {
|
||||||
DoricRegistry *registry = value.nonretainedObjectValue;
|
|
||||||
if (registry) {
|
if (registry) {
|
||||||
[library load:registry];
|
[library load:registry];
|
||||||
}
|
}
|
||||||
@ -109,8 +108,7 @@ + (void)register:(DoricLibrary *)library {
|
|||||||
|
|
||||||
+ (void)setEnvironmentValue:(NSDictionary *)value {
|
+ (void)setEnvironmentValue:(NSDictionary *)value {
|
||||||
[DoricLibraries.instance.envDic addEntriesFromDictionary:value];
|
[DoricLibraries.instance.envDic addEntriesFromDictionary:value];
|
||||||
for (NSValue *val in DoricLibraries.instance.registries) {
|
for (DoricRegistry *registry in DoricLibraries.instance.registries) {
|
||||||
DoricRegistry *registry = val.nonretainedObjectValue;
|
|
||||||
if (registry) {
|
if (registry) {
|
||||||
[registry innerSetEnvironmentValue:value];
|
[registry innerSetEnvironmentValue:value];
|
||||||
}
|
}
|
||||||
@ -124,13 +122,12 @@ - (instancetype)initWithJSEngine:(DoricJSEngine *)jsEngine {
|
|||||||
_plugins = [NSMutableDictionary new];
|
_plugins = [NSMutableDictionary new];
|
||||||
_nodes = [NSMutableDictionary new];
|
_nodes = [NSMutableDictionary new];
|
||||||
_monitors = [NSMutableSet new];
|
_monitors = [NSMutableSet new];
|
||||||
NSValue *value = [NSValue valueWithNonretainedObject:self];
|
|
||||||
[self innerRegister];
|
[self innerRegister];
|
||||||
[DoricLibraries.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) {
|
[DoricLibraries.instance.libraries enumerateObjectsUsingBlock:^(DoricLibrary *obj, BOOL *stop) {
|
||||||
[obj load:self];
|
[obj load:self];
|
||||||
}];
|
}];
|
||||||
[jsEngine setEnvironmentValue:DoricLibraries.instance.envDic];
|
[jsEngine setEnvironmentValue:DoricLibraries.instance.envDic];
|
||||||
[DoricLibraries.instance.registries addObject:value];
|
[DoricLibraries.instance.registries addObject:self];
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user