From d909a8af01e3904f89e9c4d6a073884cb51a9cd7 Mon Sep 17 00:00:00 2001 From: Garrett Moon Date: Mon, 26 Sep 2016 14:41:58 -0700 Subject: [PATCH] I don't believe it's safe to return a vector by reference created in a function. (#2286) --- AsyncDisplayKit/Private/ASLayoutTransition.mm | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/AsyncDisplayKit/Private/ASLayoutTransition.mm b/AsyncDisplayKit/Private/ASLayoutTransition.mm index 1c3bf9b818..dbe95dc75a 100644 --- a/AsyncDisplayKit/Private/ASLayoutTransition.mm +++ b/AsyncDisplayKit/Private/ASLayoutTransition.mm @@ -130,16 +130,16 @@ static inline BOOL ASLayoutCanTransitionAsynchronous(ASLayout *layout) { compareBlock:^BOOL(ASLayout *lhs, ASLayout *rhs) { return ASObjectIsEqual(lhs.layoutable, rhs.layoutable); }]; - findNodesInLayoutAtIndexes(pendingLayout, insertions, &_insertedSubnodes, &_insertedSubnodePositions); - findNodesInLayoutAtIndexesWithFilteredNodes(previousLayout, - deletions, - _insertedSubnodes, - &_removedSubnodes, - &_removedSubnodePositions); + _insertedSubnodePositions = findNodesInLayoutAtIndexes(pendingLayout, insertions, &_insertedSubnodes); + _removedSubnodePositions = findNodesInLayoutAtIndexesWithFilteredNodes(previousLayout, + deletions, + _insertedSubnodes, + &_removedSubnodes); } else { NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [pendingLayout.sublayouts count])]; - findNodesInLayoutAtIndexes(pendingLayout, indexes, &_insertedSubnodes, &_insertedSubnodePositions); + _insertedSubnodePositions = findNodesInLayoutAtIndexes(pendingLayout, indexes, &_insertedSubnodes); _removedSubnodes = nil; + _removedSubnodePositions.clear(); } _calculatedSubnodeOperations = YES; } @@ -195,26 +195,25 @@ static inline BOOL ASLayoutCanTransitionAsynchronous(ASLayout *layout) { /** * @abstract Stores the nodes at the given indexes in the `storedNodes` array, storing indexes in a `storedPositions` c++ vector. */ -static inline void findNodesInLayoutAtIndexes(ASLayout *layout, - NSIndexSet *indexes, - NSArray * __strong *storedNodes, - std::vector *storedPositions) +static inline std::vector findNodesInLayoutAtIndexes(ASLayout *layout, + NSIndexSet *indexes, + NSArray * __strong *storedNodes) { - findNodesInLayoutAtIndexesWithFilteredNodes(layout, indexes, nil, storedNodes, storedPositions); + return findNodesInLayoutAtIndexesWithFilteredNodes(layout, indexes, nil, storedNodes); } /** * @abstract Stores the nodes at the given indexes in the `storedNodes` array, storing indexes in a `storedPositions` c++ vector. * @discussion If the node exists in the `filteredNodes` array, the node is not added to `storedNodes`. */ -static inline void findNodesInLayoutAtIndexesWithFilteredNodes(ASLayout *layout, - NSIndexSet *indexes, - NSArray *filteredNodes, - NSArray * __strong *storedNodes, - std::vector *storedPositions) +static inline std::vector findNodesInLayoutAtIndexesWithFilteredNodes(ASLayout *layout, + NSIndexSet *indexes, + NSArray *filteredNodes, + NSArray * __strong *storedNodes) { NSMutableArray *nodes = [NSMutableArray arrayWithCapacity:indexes.count]; std::vector positions = std::vector(); + // From inspection, this is how enumerateObjectsAtIndexes: works under the hood NSUInteger firstIndex = indexes.firstIndex; NSUInteger lastIndex = indexes.lastIndex; @@ -236,7 +235,8 @@ static inline void findNodesInLayoutAtIndexesWithFilteredNodes(ASLayout *layout, idx += 1; } *storedNodes = nodes; - *storedPositions = positions; + + return positions; } @end