mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-10 14:35:42 +00:00
Use unsigned integers for findNodes vectors
Summary: Also refector logic and naming to be simpler and more descriptive Reviewers: schneider, chris, scottg Reviewed By: schneider, chris, scottg Subscribers: chris, jenkins Differential Revision: https://phabricator.pinadmin.com/D83911
This commit is contained in:
parent
b3d6b545f8
commit
2cb6969c79
@ -23,8 +23,8 @@
|
|||||||
BOOL _calculatedSubnodeOperations;
|
BOOL _calculatedSubnodeOperations;
|
||||||
NSArray<ASDisplayNode *> *_insertedSubnodes;
|
NSArray<ASDisplayNode *> *_insertedSubnodes;
|
||||||
NSArray<ASDisplayNode *> *_removedSubnodes;
|
NSArray<ASDisplayNode *> *_removedSubnodes;
|
||||||
std::vector<NSInteger> _insertedSubnodePositions;
|
std::vector<NSUInteger> _insertedSubnodePositions;
|
||||||
std::vector<NSInteger> _removedSubnodePositions;
|
std::vector<NSUInteger> _removedSubnodePositions;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype)initWithNode:(ASDisplayNode *)node
|
- (instancetype)initWithNode:(ASDisplayNode *)node
|
||||||
@ -48,8 +48,8 @@
|
|||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_propertyLock);
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
[self calculateSubnodeOperationsIfNeeded];
|
[self calculateSubnodeOperationsIfNeeded];
|
||||||
for (NSInteger i = 0; i < [_insertedSubnodes count]; i++) {
|
for (NSUInteger i = 0; i < [_insertedSubnodes count]; i++) {
|
||||||
NSInteger p = _insertedSubnodePositions[i];
|
NSUInteger p = _insertedSubnodePositions[i];
|
||||||
[_node insertSubnode:_insertedSubnodes[i] atIndex:p];
|
[_node insertSubnode:_insertedSubnodes[i] atIndex:p];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@
|
|||||||
{
|
{
|
||||||
ASDN::MutexLocker l(_propertyLock);
|
ASDN::MutexLocker l(_propertyLock);
|
||||||
[self calculateSubnodeOperationsIfNeeded];
|
[self calculateSubnodeOperationsIfNeeded];
|
||||||
for (NSInteger i = 0; i < [_removedSubnodes count]; i++) {
|
for (NSUInteger i = 0; i < [_removedSubnodes count]; i++) {
|
||||||
[_removedSubnodes[i] removeFromSupernode];
|
[_removedSubnodes[i] removeFromSupernode];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -77,15 +77,15 @@
|
|||||||
compareBlock:^BOOL(ASLayout *lhs, ASLayout *rhs) {
|
compareBlock:^BOOL(ASLayout *lhs, ASLayout *rhs) {
|
||||||
return ASObjectIsEqual(lhs.layoutableObject, rhs.layoutableObject);
|
return ASObjectIsEqual(lhs.layoutableObject, rhs.layoutableObject);
|
||||||
}];
|
}];
|
||||||
filterNodesInLayoutAtIndexes(_pendingLayout, insertions, &_insertedSubnodes, &_insertedSubnodePositions);
|
findNodesInLayoutAtIndexes(_pendingLayout, insertions, &_insertedSubnodes, &_insertedSubnodePositions);
|
||||||
filterNodesInLayoutAtIndexesWithIntersectingNodes(_previousLayout,
|
findNodesInLayoutAtIndexesWithFilteredNodes(_previousLayout,
|
||||||
deletions,
|
deletions,
|
||||||
_insertedSubnodes,
|
_insertedSubnodes,
|
||||||
&_removedSubnodes,
|
&_removedSubnodes,
|
||||||
&_removedSubnodePositions);
|
&_removedSubnodePositions);
|
||||||
} else {
|
} else {
|
||||||
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [_pendingLayout.immediateSublayouts count])];
|
NSIndexSet *indexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [_pendingLayout.immediateSublayouts count])];
|
||||||
filterNodesInLayoutAtIndexes(_pendingLayout, indexes, &_insertedSubnodes, &_insertedSubnodePositions);
|
findNodesInLayoutAtIndexes(_pendingLayout, indexes, &_insertedSubnodes, &_insertedSubnodePositions);
|
||||||
_removedSubnodes = nil;
|
_removedSubnodes = nil;
|
||||||
}
|
}
|
||||||
_calculatedSubnodeOperations = YES;
|
_calculatedSubnodeOperations = YES;
|
||||||
@ -142,42 +142,31 @@
|
|||||||
/**
|
/**
|
||||||
* @abstract Stores the nodes at the given indexes in the `storedNodes` array, storing indexes in a `storedPositions` c++ vector.
|
* @abstract Stores the nodes at the given indexes in the `storedNodes` array, storing indexes in a `storedPositions` c++ vector.
|
||||||
*/
|
*/
|
||||||
static inline void filterNodesInLayoutAtIndexes(
|
static inline void findNodesInLayoutAtIndexes(ASLayout *layout,
|
||||||
ASLayout *layout,
|
NSIndexSet *indexes,
|
||||||
NSIndexSet *indexes,
|
NSArray<ASDisplayNode *> * __strong *storedNodes,
|
||||||
NSArray<ASDisplayNode *> * __strong *storedNodes,
|
std::vector<NSUInteger> *storedPositions)
|
||||||
std::vector<NSInteger> *storedPositions
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
filterNodesInLayoutAtIndexesWithIntersectingNodes(layout, indexes, nil, storedNodes, storedPositions);
|
findNodesInLayoutAtIndexesWithFilteredNodes(layout, indexes, nil, storedNodes, storedPositions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @abstract Stores the nodes at the given indexes in the `storedNodes` array, storing indexes in a `storedPositions` c++ vector.
|
* @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 `intersectingNodes` array, the node is not added to `storedNodes`.
|
* @discussion If the node exists in the `filteredNodes` array, the node is not added to `storedNodes`.
|
||||||
*/
|
*/
|
||||||
static inline void filterNodesInLayoutAtIndexesWithIntersectingNodes(
|
static inline void findNodesInLayoutAtIndexesWithFilteredNodes(ASLayout *layout,
|
||||||
ASLayout *layout,
|
NSIndexSet *indexes,
|
||||||
NSIndexSet *indexes,
|
NSArray<ASDisplayNode *> *filteredNodes,
|
||||||
NSArray<ASDisplayNode *> *intersectingNodes,
|
NSArray<ASDisplayNode *> * __strong *storedNodes,
|
||||||
NSArray<ASDisplayNode *> * __strong *storedNodes,
|
std::vector<NSUInteger> *storedPositions)
|
||||||
std::vector<NSInteger> *storedPositions
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
NSMutableArray<ASDisplayNode *> *nodes = [NSMutableArray array];
|
NSMutableArray<ASDisplayNode *> *nodes = [NSMutableArray array];
|
||||||
std::vector<NSInteger> positions = std::vector<NSInteger>();
|
std::vector<NSUInteger> positions = std::vector<NSUInteger>();
|
||||||
NSInteger idx = [indexes firstIndex];
|
NSUInteger idx = [indexes firstIndex];
|
||||||
while (idx != NSNotFound) {
|
while (idx != NSNotFound) {
|
||||||
BOOL skip = NO;
|
|
||||||
ASDisplayNode *node = (ASDisplayNode *)layout.immediateSublayouts[idx].layoutableObject;
|
ASDisplayNode *node = (ASDisplayNode *)layout.immediateSublayouts[idx].layoutableObject;
|
||||||
ASDisplayNodeCAssert(node, @"A flattened layout must consist exclusively of node sublayouts");
|
ASDisplayNodeCAssert(node, @"A flattened layout must consist exclusively of node sublayouts");
|
||||||
for (ASDisplayNode *i in intersectingNodes) {
|
if (node != nil && [filteredNodes indexOfObjectIdenticalTo:node] != NSNotFound) {
|
||||||
if (node == i) {
|
|
||||||
skip = YES;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!skip) {
|
|
||||||
[nodes addObject:node];
|
[nodes addObject:node];
|
||||||
positions.push_back(idx);
|
positions.push_back(idx);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user