From 8bfc4b26c3a43d25eb82fd7ef98d0db056d0daa7 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Thu, 31 Aug 2023 19:10:16 -0400 Subject: [PATCH] Address some review comments on Darwin controller data store. 1) More efficient copying of arrays. 2) Make it clear what classes need to go in our storage class list. --- src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm index 4732009ade3513..7336b27f225cee 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.mm @@ -138,8 +138,7 @@ - (nullable instancetype)initWithController:(MTRDeviceController *)controller return nil; } } - _nodesWithResumptionInfo = [NSMutableArray arrayWithCapacity:[resumptionNodeList count]]; - [_nodesWithResumptionInfo addObjectsFromArray:resumptionNodeList]; + _nodesWithResumptionInfo = [resumptionNodeList mutableCopy]; } else { _nodesWithResumptionInfo = [[NSMutableArray alloc] init]; } @@ -184,7 +183,7 @@ - (void)storeResumptionInfo:(MTRCASESessionResumptionInfo *)resumptionInfo // Update our resumption info node list. [_nodesWithResumptionInfo addObject:resumptionInfo.nodeID]; [_storageDelegate controller:_controller - storeValue:[NSArray arrayWithArray:_nodesWithResumptionInfo] + storeValue:[_nodesWithResumptionInfo copy] forKey:sResumptionNodeListKey securityLevel:MTRStorageSecurityLevelSecure sharingType:MTRStorageSharingTypeNotShared]; @@ -349,6 +348,9 @@ - (void)encodeWithCoder:(NSCoder *)coder NSSet * MTRDeviceControllerStorageClasses() { + // This only needs to return the classes for toplevel things we are storing, + // plus NSNumber because some archivers use that internally to store + // information about what's being archived. static NSSet * const sStorageClasses = [NSSet setWithArray:@[ [NSNumber class], [NSData class],