Skip to content

Commit 871b16d

Browse files
Apply suggestions from code review
Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent e49d091 commit 871b16d

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+13-15
Original file line numberDiff line numberDiff line change
@@ -1904,9 +1904,8 @@ - (void)_removeCachedAttribute:(NSNumber *)attributeID fromCluster:(MTRClusterPa
19041904
if (_clusterDataToPersist == nil) {
19051905
return;
19061906
}
1907-
auto * clusterData = [_clusterDataToPersist objectForKey:clusterPath];
1907+
auto * clusterData = _clusterDataToPersist[clusterPath];
19081908
[clusterData removeValueForAttribute:attributeID];
1909-
[_clusterDataToPersist setObject:clusterData forKey:clusterPath];
19101909
}
19111910

19121911
- (void)_createDataVersionFilterListFromDictionary:(NSDictionary<MTRClusterPath *, NSNumber *> *)dataVersions dataVersionFilterList:(DataVersionFilter **)dataVersionFilterList count:(size_t *)count sizeReduction:(size_t)sizeReduction
@@ -3033,7 +3032,7 @@ - (BOOL)_attributeAffectsDeviceConfiguration:(MTRAttributePath *)attributePath
30333032
return NO;
30343033
}
30353034

3036-
- (void)_removeClusters:(NSSet *)clusterPathsToRemove
3035+
- (void)_removeClusters:(NSSet<MTRClusterPath *> *)clusterPathsToRemove
30373036
{
30383037
os_unfair_lock_assert_owner(&self->_lock);
30393038

@@ -3047,7 +3046,7 @@ - (void)_removeClusters:(NSSet *)clusterPathsToRemove
30473046
}
30483047
}
30493048

3050-
- (void)_removeAttributes:(NSSet *)toBeRemovedAttributes fromCluster:(MTRClusterPath *)clusterPathToRemoveAttributesFrom
3049+
- (void)_removeAttributes:(NSSet<NSNumber *> *)attributes fromCluster:(MTRClusterPath *)clusterPath
30513050
{
30523051
if (toBeRemovedAttributes == nil || clusterPathToRemoveAttributesFrom == nil) {
30533052
return;
@@ -3057,15 +3056,17 @@ - (void)_removeAttributes:(NSSet *)toBeRemovedAttributes fromCluster:(MTRCluster
30573056
for (NSNumber * attribute in toBeRemovedAttributes) {
30583057
[self _removeCachedAttribute:attribute fromCluster:clusterPathToRemoveAttributesFrom];
30593058
}
3059+
// Just clear out the NSCache entry for this cluster, so we'll load it from storage as needed.
30603060
[_persistedClusterData removeObjectForKey:clusterPathToRemoveAttributesFrom];
30613061
[self.deviceController.controllerDataStore clearStoredClusterDataForNodeID:self.nodeID endpointID:clusterPathToRemoveAttributesFrom.endpoint clusterID:clusterPathToRemoveAttributesFrom.cluster];
30623062
}
30633063

3064-
- (void)_pruneOrphanedEndpoints:(NSDictionary *)previousPartsListValue
3065-
newPartsListValue:(NSDictionary *)newPartsListValue
3064+
- (void)_pruneEndpointsIn:(NSDictionary *)previousPartsListValue
3065+
missingFrom:(NSDictionary *)newPartsListValue
30663066
{
3067-
// If the parts list changed and one or more endpoints were removed, remove all the clusters in _persistedClusters, _persistedClusterData and _clusterDataToPersist for all those endpoints.
3068-
// Also remove it from the data store.
3067+
// If the parts list changed and one or more endpoints were removed, remove all the
3068+
// clusters for all those endpoints from our data structures.
3069+
// Also remove those endpoints from the data store.
30693070
NSMutableSet * toBeRemovedEndpoints = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _dataValueWithoutDataVersion:previousPartsListValue]]];
30703071
NSSet * endpointsOnDevice = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:newPartsListValue]];
30713072
[toBeRemovedEndpoints minusSet:endpointsOnDevice];
@@ -3086,7 +3087,7 @@ - (void)_pruneOrphanedClusters:(MTRAttributePath *)attributePath
30863087
previousServerListValue:(NSDictionary *)previousServerListValue
30873088
newServerListValue:(NSDictionary *)newServerListValue
30883089
{
3089-
// If the server list changed and clusters were removed, remove the clusters from the _persistedClusters, _persistedClusterData and _clusterDataToPersist for all those clusters.
3090+
// If the server list changed and clusters were removed, remove those clusters from our data structures.
30903091
// Also remove it from the data store.
30913092
NSMutableSet<NSNumber *> * toBeRemovedClusters = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _dataValueWithoutDataVersion:previousServerListValue]]];
30923093
NSSet<NSNumber *> * clustersStillOnEndpoint = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:newServerListValue]];
@@ -3106,8 +3107,8 @@ - (void)_pruneOrphanedClusters:(MTRAttributePath *)attributePath
31063107
- (void)_pruneOrphanedAttributes:(MTRAttributePath *)attributePath
31073108
newAttributeListValue:(NSDictionary *)newAttributeListValue
31083109
{
3109-
// If the attribute list changed and attributes were removed, remove the attributes from the _clusterDataToPersist for that cluster and endpoint.
3110-
// Clear out the _peristedClusterData and data store cluster data. Update the data storage with updated cluster data.
3110+
// If the attribute list changed and attributes were removed, remove the attributes from our
3111+
// data structures.
31113112
NSMutableSet<NSNumber *> * toBeRemovedAttributes = [NSMutableSet setWithArray:[self arrayOfNumbersFromAttributeValue:[self _cachedAttributeValueForPath:attributePath]]];
31123113
NSSet<NSNumber *> * attributesStillInCluster = [NSSet setWithArray:[self arrayOfNumbersFromAttributeValue:newAttributeListValue]];
31133114

@@ -3376,10 +3377,7 @@ - (BOOL)_clusterHasBeenPersisted:(MTRClusterPath *)path
33763377
{
33773378
std::lock_guard lock(_lock);
33783379

3379-
if ([_persistedClusters containsObject:path]) {
3380-
return YES;
3381-
}
3382-
return NO;
3380+
return [_persistedClusters containsObject:path];
33833381
}
33843382
#endif
33853383

0 commit comments

Comments
 (0)