From a11506564a8ea02fec8c87a18c5430863093c21c Mon Sep 17 00:00:00 2001 From: Adlai Holler Date: Fri, 15 Jun 2018 10:15:25 -0700 Subject: [PATCH] Reduce usage of autorelease pools (#968) * Reduce reliance on the autorelease pool * changelog * A few more places * Use it in another place --- CHANGELOG.md | 1 + Source/ASCollectionView.mm | 6 +++--- Source/ASDisplayNode+Layout.mm | 6 +++--- Source/ASDisplayNode+Yoga.mm | 2 +- Source/ASDisplayNodeExtras.mm | 4 ++-- Source/ASNetworkImageNode.mm | 6 +++--- Source/ASRunLoopQueue.mm | 14 ++++++-------- Source/ASTableView.mm | 2 +- Source/ASTextNode.mm | 2 +- Source/Base/ASBaseDefines.h | 8 +++++--- Source/Details/ASBasicImageDownloader.mm | 2 +- Source/Details/ASCollectionLayoutState.mm | 6 +++--- Source/Details/ASDataController.mm | 6 +++--- Source/Details/ASPageTable.m | 2 +- Source/Details/NSArray+Diffing.m | 6 +++--- Source/Details/NSIndexSet+ASHelpers.h | 2 -- Source/Details/NSIndexSet+ASHelpers.m | 19 ++++--------------- Source/Details/_ASDisplayViewAccessiblity.mm | 6 +++--- Source/Layout/ASLayout.mm | 4 ++-- Source/Layout/ASStackLayoutSpec.mm | 2 +- Source/Private/ASDisplayNode+AsyncDisplay.mm | 2 +- Source/Private/ASMutableElementMap.m | 6 +++--- Source/Private/ASTwoDimensionalArrayUtils.m | 4 ++-- .../TextExperiment/Component/ASTextLayout.m | 6 +++--- Source/Private/_ASHierarchyChangeSet.mm | 16 ++++++++-------- Source/_ASTransitionContext.m | 6 +++--- 26 files changed, 67 insertions(+), 79 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aba12d810..fec567fd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Internal housekeeping on the async transaction (rendering) system. [Adlai Holler](https://github.com/Adlai-Holler) - Add new protocol `ASLocking` that extends `NSLocking` with `tryLock`, and allows taking multiple locks safely. [Adlai Holler](https://github.com/Adlai-Holler) - Make the main thread ivar deallocation system available to other classes. Plus a little optimization. See `ASMainThreadDeallocation.h`. [Adlai Holler](https://github.com/Adlai-Holler) [#959](https://github.com/TextureGroup/Texture/pull/959) +- Reduce usage of autorelease pools. [Adlai Holler](https://github.com/Adlai-Holler) [#968](https://github.com/TextureGroup/Texture/pull/968) ## 2.7 - Fix pager node for interface coalescing. [Max Wang](https://github.com/wsdwsd0829) [#877](https://github.com/TextureGroup/Texture/pull/877) diff --git a/Source/ASCollectionView.mm b/Source/ASCollectionView.mm index 3b8964686..ea19cbca5 100644 --- a/Source/ASCollectionView.mm +++ b/Source/ASCollectionView.mm @@ -303,7 +303,7 @@ - (instancetype)_initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionV _proxyDataSource = [[ASCollectionViewProxy alloc] initWithTarget:nil interceptor:self]; super.dataSource = (id)_proxyDataSource; - _registeredSupplementaryKinds = [NSMutableSet set]; + _registeredSupplementaryKinds = [[NSMutableSet alloc] init]; _visibleElements = [[NSCountedSet alloc] init]; _cellsForVisibilityUpdates = [NSHashTable hashTableWithOptions:NSHashTableObjectPointerPersonality]; @@ -1729,7 +1729,7 @@ - (void)layoutSubviews NSArray *nodes = [_cellsForLayoutUpdates allObjects]; [_cellsForLayoutUpdates removeAllObjects]; - NSMutableArray *nodesSizeChanged = [NSMutableArray array]; + NSMutableArray *nodesSizeChanged = [[NSMutableArray alloc] init]; [_dataController relayoutNodes:nodes nodesSizeChanged:nodesSizeChanged]; [self nodesDidRelayout:nodesSizeChanged]; @@ -2005,7 +2005,7 @@ - (ASCellNodeBlock)dataController:(ASDataController *)dataController supplementa - (NSArray *)dataController:(ASDataController *)dataController supplementaryNodeKindsInSections:(NSIndexSet *)sections { if (_asyncDataSourceFlags.collectionNodeSupplementaryElementKindsInSection) { - NSMutableSet *kinds = [NSMutableSet set]; + auto kinds = [[NSMutableSet alloc] init]; GET_COLLECTIONNODE_OR_RETURN(collectionNode, @[]); [sections enumerateIndexesUsingBlock:^(NSUInteger section, BOOL * _Nonnull stop) { NSArray *kindsForSection = [_asyncDataSource collectionNode:collectionNode supplementaryElementKindsInSection:section]; diff --git a/Source/ASDisplayNode+Layout.mm b/Source/ASDisplayNode+Layout.mm index 2876e68c4..239057e33 100644 --- a/Source/ASDisplayNode+Layout.mm +++ b/Source/ASDisplayNode+Layout.mm @@ -767,10 +767,10 @@ - (void)animateLayoutTransition:(id)context NSArray *removedSubnodes = [context removedSubnodes]; NSMutableArray *insertedSubnodes = [[context insertedSubnodes] mutableCopy]; - NSMutableArray *movedSubnodes = [NSMutableArray array]; + auto movedSubnodes = [[NSMutableArray alloc] init]; - NSMutableArray<_ASAnimatedTransitionContext *> *insertedSubnodeContexts = [NSMutableArray array]; - NSMutableArray<_ASAnimatedTransitionContext *> *removedSubnodeContexts = [NSMutableArray array]; + auto insertedSubnodeContexts = [[NSMutableArray<_ASAnimatedTransitionContext *> alloc] init]; + auto removedSubnodeContexts = [[NSMutableArray<_ASAnimatedTransitionContext *> alloc] init]; for (ASDisplayNode *subnode in [context subnodesForKey:ASTransitionContextToLayoutKey]) { if ([insertedSubnodes containsObject:subnode] == NO) { diff --git a/Source/ASDisplayNode+Yoga.mm b/Source/ASDisplayNode+Yoga.mm index 078559639..ea5af2bb6 100644 --- a/Source/ASDisplayNode+Yoga.mm +++ b/Source/ASDisplayNode+Yoga.mm @@ -80,7 +80,7 @@ - (void)insertYogaChild:(ASDisplayNode *)child atIndex:(NSUInteger)index return; } if (_yogaChildren == nil) { - _yogaChildren = [NSMutableArray array]; + _yogaChildren = [[NSMutableArray alloc] init]; } // Clean up state in case this child had another parent. diff --git a/Source/ASDisplayNodeExtras.mm b/Source/ASDisplayNodeExtras.mm index 480aa1cf9..651a3424e 100644 --- a/Source/ASDisplayNodeExtras.mm +++ b/Source/ASDisplayNodeExtras.mm @@ -178,7 +178,7 @@ static void _ASCollectDisplayNodes(NSMutableArray *array, CALayer *layer) extern NSArray *ASCollectDisplayNodes(ASDisplayNode *node) { - NSMutableArray *list = [NSMutableArray array]; + NSMutableArray *list = [[NSMutableArray alloc] init]; for (CALayer *sublayer in node.layer.sublayers) { _ASCollectDisplayNodes(list, sublayer); } @@ -203,7 +203,7 @@ static void _ASDisplayNodeFindAllSubnodes(NSMutableArray *array, ASDisplayNode * extern NSArray *ASDisplayNodeFindAllSubnodes(ASDisplayNode *start, BOOL (^block)(ASDisplayNode *node)) { - NSMutableArray *list = [NSMutableArray array]; + NSMutableArray *list = [[NSMutableArray alloc] init]; _ASDisplayNodeFindAllSubnodes(list, start, block); return list; } diff --git a/Source/ASNetworkImageNode.mm b/Source/ASNetworkImageNode.mm index 3cee8185d..f28e063ff 100755 --- a/Source/ASNetworkImageNode.mm +++ b/Source/ASNetworkImageNode.mm @@ -629,20 +629,20 @@ - (void)_lazilyLoadImageIfNecessary } else { // First try to load the path directly, for efficiency assuming a developer who // doesn't want caching is trying to be as minimal as possible. - UIImage *nonAnimatedImage = [UIImage imageWithContentsOfFile:URL.path]; + auto nonAnimatedImage = [[UIImage alloc] initWithContentsOfFile:URL.path]; if (nonAnimatedImage == nil) { // If we couldn't find it, execute an -imageNamed:-like search so we can find resources even if the // extension is not provided in the path. This allows the same path to work regardless of shouldCacheImage. NSString *filename = [[NSBundle mainBundle] pathForResource:URL.path.lastPathComponent ofType:nil]; if (filename != nil) { - nonAnimatedImage = [UIImage imageWithContentsOfFile:filename]; + nonAnimatedImage = [[UIImage alloc] initWithContentsOfFile:filename]; } } // If the file may be an animated gif and then created an animated image. id animatedImage = nil; if (_downloaderFlags.downloaderImplementsAnimatedImage) { - NSData *data = [NSData dataWithContentsOfURL:URL]; + auto data = [[NSData alloc] initWithContentsOfURL:URL]; if (data != nil) { animatedImage = [_downloader animatedImageWithData:data]; diff --git a/Source/ASRunLoopQueue.mm b/Source/ASRunLoopQueue.mm index fd043d5d0..1ac258b2b 100644 --- a/Source/ASRunLoopQueue.mm +++ b/Source/ASRunLoopQueue.mm @@ -238,14 +238,12 @@ - (void)releaseObjectInBackground:(id _Nullable __strong *)objectPtr - (void)drain { - @autoreleasepool { - _lock.lock(); - auto q = std::move(_queue); - _lock.unlock(); - for (auto ref : q) { - // NOTE: Could check that retain count is 1 and retry later if not. - CFRelease(ref); - } + _lock.lock(); + auto q = std::move(_queue); + _lock.unlock(); + for (auto ref : q) { + // NOTE: Could check that retain count is 1 and retry later if not. + CFRelease(ref); } } diff --git a/Source/ASTableView.mm b/Source/ASTableView.mm index 1894b421f..cbb7dac90 100644 --- a/Source/ASTableView.mm +++ b/Source/ASTableView.mm @@ -758,7 +758,7 @@ - (void)layoutSubviews NSArray *nodes = [_cellsForLayoutUpdates allObjects]; [_cellsForLayoutUpdates removeAllObjects]; - NSMutableArray *nodesSizeChanged = [NSMutableArray array]; + auto nodesSizeChanged = [[NSMutableArray alloc] init]; [_dataController relayoutNodes:nodes nodesSizeChanged:nodesSizeChanged]; if (nodesSizeChanged.count > 0) { [self requeryNodeHeights]; diff --git a/Source/ASTextNode.mm b/Source/ASTextNode.mm index 55c830a2f..428a19b2c 100644 --- a/Source/ASTextNode.mm +++ b/Source/ASTextNode.mm @@ -854,7 +854,7 @@ - (NSArray *)_rectsForTextRange:(NSRange)textRange measureOption:(ASTextKitRende ASLockScopeSelf(); NSArray *rects = [[self _locked_renderer] rectsForTextRange:textRange measureOption:measureOption]; - NSMutableArray *adjustedRects = [NSMutableArray array]; + auto adjustedRects = [[NSMutableArray alloc] init]; for (NSValue *rectValue in rects) { CGRect rect = [rectValue CGRectValue]; diff --git a/Source/Base/ASBaseDefines.h b/Source/Base/ASBaseDefines.h index 6706b6da4..b274aefa1 100755 --- a/Source/Base/ASBaseDefines.h +++ b/Source/Base/ASBaseDefines.h @@ -259,7 +259,7 @@ * Create a new set by mapping `collection` over `work`, ignoring nil. */ #define ASSetByFlatMapping(collection, decl, work) ({ \ - NSMutableSet *s = [NSMutableSet set]; \ + NSMutableSet *s = [[NSMutableSet alloc] init]; \ for (decl in collection) {\ id result = work; \ if (result != nil) { \ @@ -271,9 +271,11 @@ /** * Create a new ObjectPointerPersonality NSHashTable by mapping `collection` over `work`, ignoring nil. + * + * capacity: 0 is taken from +hashTableWithOptions. */ #define ASPointerTableByFlatMapping(collection, decl, work) ({ \ - NSHashTable *t = [NSHashTable hashTableWithOptions:NSHashTableObjectPointerPersonality]; \ + NSHashTable *t = [[NSHashTable alloc] initWithOptions:NSHashTableObjectPointerPersonality capacity:0]; \ for (decl in collection) {\ id result = work; \ if (result != nil) { \ @@ -287,7 +289,7 @@ * Create a new array by mapping `collection` over `work`, ignoring nil. */ #define ASArrayByFlatMapping(collection, decl, work) ({ \ - NSMutableArray *a = [NSMutableArray array]; \ + NSMutableArray *a = [[NSMutableArray alloc] init]; \ for (decl in collection) {\ id result = work; \ if (result != nil) { \ diff --git a/Source/Details/ASBasicImageDownloader.mm b/Source/Details/ASBasicImageDownloader.mm index bdb73b92a..33b5244ce 100644 --- a/Source/Details/ASBasicImageDownloader.mm +++ b/Source/Details/ASBasicImageDownloader.mm @@ -245,7 +245,7 @@ - (id)downloadImageWithURL:(NSURL *)URL // cause significant performance issues. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ // associate metadata with it - NSMutableDictionary *callbackData = [NSMutableDictionary dictionary]; + NSMutableDictionary *callbackData = [[NSMutableDictionary alloc] init]; callbackData[kASBasicImageDownloaderContextCallbackQueue] = callbackQueue ? : dispatch_get_main_queue(); if (downloadProgress) { diff --git a/Source/Details/ASCollectionLayoutState.mm b/Source/Details/ASCollectionLayoutState.mm index 348f9a549..6aae8aa26 100644 --- a/Source/Details/ASCollectionLayoutState.mm +++ b/Source/Details/ASCollectionLayoutState.mm @@ -159,7 +159,7 @@ - (UICollectionViewLayoutAttributes *)layoutAttributesForElement:(ASCollectionEl } // Use a set here because some items may span multiple pages - NSMutableSet *result = [NSMutableSet set]; + auto result = [[NSMutableSet alloc] init]; for (id pagePtr in pages) { ASPageCoordinate page = (ASPageCoordinate)pagePtr; NSArray *allAttrs = [_pageToLayoutAttributesTable objectForPage:page]; @@ -216,7 +216,7 @@ - (ASPageToLayoutAttributesTable *)getAndRemoveUnmeasuredLayoutAttributesPageTab for (UICollectionViewLayoutAttributes *attrs in attrsInPage) { if (CGRectIntersectsRect(rect, attrs.frame)) { if (intersectingAttrsInPage == nil) { - intersectingAttrsInPage = [NSMutableArray array]; + intersectingAttrsInPage = [[NSMutableArray alloc] init]; } [intersectingAttrsInPage addObject:attrs]; } @@ -245,7 +245,7 @@ + (ASPageToLayoutAttributesTable *)_unmeasuredLayoutAttributesTableFromTable:(NS contentSize:(CGSize)contentSize pageSize:(CGSize)pageSize { - NSMutableArray *unmeasuredAttrs = [NSMutableArray array]; + NSMutableArray *unmeasuredAttrs = [[NSMutableArray alloc] init]; for (ASCollectionElement *element in table) { UICollectionViewLayoutAttributes *attrs = [table objectForKey:element]; if (element.nodeIfAllocated == nil || CGSizeEqualToSize(element.nodeIfAllocated.calculatedSize, attrs.frame.size) == NO) { diff --git a/Source/Details/ASDataController.mm b/Source/Details/ASDataController.mm index e1b25c634..845d9c10b 100644 --- a/Source/Details/ASDataController.mm +++ b/Source/Details/ASDataController.mm @@ -123,7 +123,7 @@ - (instancetype)initWithDataSource:(id)dataSource node:( _mainSerialQueue = [[ASMainSerialQueue alloc] init]; _synchronized = YES; - _onDidFinishSynchronizingBlocks = [NSMutableSet set]; + _onDidFinishSynchronizingBlocks = [[NSMutableSet alloc] init]; const char *queueName = [[NSString stringWithFormat:@"org.AsyncDisplayKit.ASDataController.editingTransactionQueue:%p", self] cStringUsingEncoding:NSASCIIStringEncoding]; _editingTransactionQueue = dispatch_queue_create(queueName, DISPATCH_QUEUE_SERIAL); @@ -214,7 +214,7 @@ - (void)_layoutNode:(ASCellNode *)node withConstrainedSize:(ASSizeRange)constrai return @[]; } - NSMutableArray *indexPaths = [NSMutableArray array]; + auto indexPaths = [[NSMutableArray alloc] init]; if ([kind isEqualToString:ASDataControllerRowNodeKind]) { std::vector counts = [self itemCountsFromDataSource]; [sections enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) { @@ -671,7 +671,7 @@ - (void)updateWithChangeSet:(_ASHierarchyChangeSet *)changeSet [layoutDelegateClass calculateLayoutWithContext:layoutContext]; completion(); } else { - NSMutableArray *elementsToProcess = [NSMutableArray array]; + auto elementsToProcess = [[NSMutableArray alloc] init]; for (ASCollectionElement *element in newMap) { ASCellNode *nodeIfAllocated = element.nodeIfAllocated; if (nodeIfAllocated.shouldUseUIKitCell) { diff --git a/Source/Details/ASPageTable.m b/Source/Details/ASPageTable.m index 6855b41b6..0410e50a8 100644 --- a/Source/Details/ASPageTable.m +++ b/Source/Details/ASPageTable.m @@ -121,7 +121,7 @@ + (ASPageToLayoutAttributesTable *)pageTableWithLayoutAttributes:(id *attrsInPage = [result objectForPage:page]; if (attrsInPage == nil) { - attrsInPage = [NSMutableArray array]; + attrsInPage = [[NSMutableArray alloc] init]; [result setObject:attrsInPage forPage:page]; } [attrsInPage addObject:attrs]; diff --git a/Source/Details/NSArray+Diffing.m b/Source/Details/NSArray+Diffing.m index 9e964e827..ee0ba0ff3 100644 --- a/Source/Details/NSArray+Diffing.m +++ b/Source/Details/NSArray+Diffing.m @@ -34,7 +34,7 @@ - (void)asdk_diffWithArray:(NSArray *)array insertions:(NSIndexSet **)insertions if (insertions) { NSArray *commonObjects = [self objectsAtIndexes:commonIndexes]; - NSMutableIndexSet *insertionIndexes = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *insertionIndexes = [[NSMutableIndexSet alloc] init]; for (NSInteger i = 0, j = 0; i < commonObjects.count || j < array.count;) { if (i < commonObjects.count && j < array.count && comparison(commonObjects[i], array[j])) { i++; j++; @@ -47,7 +47,7 @@ - (void)asdk_diffWithArray:(NSArray *)array insertions:(NSIndexSet **)insertions } if (deletions) { - NSMutableIndexSet *deletionIndexes = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *deletionIndexes = [[NSMutableIndexSet alloc] init]; for (NSInteger i = 0; i < self.count; i++) { if (![commonIndexes containsIndex:i]) { [deletionIndexes addIndex:i]; @@ -90,7 +90,7 @@ - (NSIndexSet *)_asdk_commonIndexesWithArray:(NSArray *)array compareBlock:(BOOL } } - NSMutableIndexSet *common = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *common = [[NSMutableIndexSet alloc] init]; NSInteger i = selfCount, j = arrayCount; while(i > 0 && j > 0) { if (comparison(self[i-1], array[j-1])) { diff --git a/Source/Details/NSIndexSet+ASHelpers.h b/Source/Details/NSIndexSet+ASHelpers.h index 18bb2f298..2ac42f96b 100644 --- a/Source/Details/NSIndexSet+ASHelpers.h +++ b/Source/Details/NSIndexSet+ASHelpers.h @@ -34,6 +34,4 @@ /// Returns all the section indexes contained in the index paths array. + (NSIndexSet *)as_sectionsFromIndexPaths:(NSArray *)indexPaths; -- (NSArray *)as_filterIndexPathsBySection:(id)indexPaths; - @end diff --git a/Source/Details/NSIndexSet+ASHelpers.m b/Source/Details/NSIndexSet+ASHelpers.m index 06743e0ad..cc097e15e 100644 --- a/Source/Details/NSIndexSet+ASHelpers.m +++ b/Source/Details/NSIndexSet+ASHelpers.m @@ -24,7 +24,7 @@ @implementation NSIndexSet (ASHelpers) - (NSIndexSet *)as_indexesByMapping:(NSUInteger (^)(NSUInteger))block { - NSMutableIndexSet *result = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *result = [[NSMutableIndexSet alloc] init]; [self enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) { for (NSUInteger i = range.location; i < NSMaxRange(range); i++) { NSUInteger newIndex = block(i); @@ -38,7 +38,7 @@ - (NSIndexSet *)as_indexesByMapping:(NSUInteger (^)(NSUInteger))block - (NSIndexSet *)as_intersectionWithIndexes:(NSIndexSet *)indexes { - NSMutableIndexSet *result = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *result = [[NSMutableIndexSet alloc] init]; [self enumerateRangesUsingBlock:^(NSRange range, BOOL * _Nonnull stop) { [indexes enumerateRangesInRange:range options:kNilOptions usingBlock:^(NSRange range, BOOL * _Nonnull stop) { [result addIndexesInRange:range]; @@ -49,7 +49,7 @@ - (NSIndexSet *)as_intersectionWithIndexes:(NSIndexSet *)indexes + (NSIndexSet *)as_indexSetFromIndexPaths:(NSArray *)indexPaths inSection:(NSUInteger)section { - NSMutableIndexSet *result = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *result = [[NSMutableIndexSet alloc] init]; for (NSIndexPath *indexPath in indexPaths) { if (indexPath.section == section) { [result addIndex:indexPath.item]; @@ -89,22 +89,11 @@ - (NSString *)as_smallDescription + (NSIndexSet *)as_sectionsFromIndexPaths:(NSArray *)indexPaths { - NSMutableIndexSet *result = [NSMutableIndexSet indexSet]; + NSMutableIndexSet *result = [[NSMutableIndexSet alloc] init]; for (NSIndexPath *indexPath in indexPaths) { [result addIndex:indexPath.section]; } return result; } -- (NSArray *)as_filterIndexPathsBySection:(id)indexPaths -{ - NSMutableArray *result = [NSMutableArray array]; - for (NSIndexPath *indexPath in indexPaths) { - if ([self containsIndex:indexPath.section]) { - [result addObject:indexPath]; - } - } - return result; -} - @end diff --git a/Source/Details/_ASDisplayViewAccessiblity.mm b/Source/Details/_ASDisplayViewAccessiblity.mm index d311cdbcd..1f336ac52 100644 --- a/Source/Details/_ASDisplayViewAccessiblity.mm +++ b/Source/Details/_ASDisplayViewAccessiblity.mm @@ -142,8 +142,8 @@ static void CollectUIAccessibilityElementsForNode(ASDisplayNode *node, ASDisplay static void CollectAccessibilityElementsForContainer(ASDisplayNode *container, _ASDisplayView *view, NSMutableArray *elements) { UIAccessibilityElement *accessiblityElement = [ASAccessibilityElement accessibilityElementWithContainer:view node:container containerNode:container]; - NSMutableArray *labeledNodes = [NSMutableArray array]; - NSMutableArray *actions = [NSMutableArray array]; + NSMutableArray *labeledNodes = [[NSMutableArray alloc] init]; + NSMutableArray *actions = [[NSMutableArray alloc] init]; std::queue queue; queue.push(container); @@ -268,7 +268,7 @@ - (NSArray *)accessibleElements return _accessibleElements; } - NSMutableArray *accessibleElements = [NSMutableArray array]; + NSMutableArray *accessibleElements = [[NSMutableArray alloc] init]; CollectAccessibilityElementsForView(self, accessibleElements); SortAccessibilityElements(accessibleElements); _accessibleElements = accessibleElements; diff --git a/Source/Layout/ASLayout.mm b/Source/Layout/ASLayout.mm index 2c71c10da..2400fa416 100644 --- a/Source/Layout/ASLayout.mm +++ b/Source/Layout/ASLayout.mm @@ -236,10 +236,10 @@ - (ASLayout *)filteredNodeLayoutTree NS_RETURNS_RETAINED queue.push_back({sublayout, sublayout.position}); } - NSMutableArray *flattenedSublayouts = [NSMutableArray array]; + NSMutableArray *flattenedSublayouts = [[NSMutableArray alloc] init]; while (!queue.empty()) { - const Context context = queue.front(); + const Context context = std::move(queue.front()); queue.pop_front(); ASLayout *layout = context.layout; diff --git a/Source/Layout/ASStackLayoutSpec.mm b/Source/Layout/ASStackLayoutSpec.mm index 756912d80..3952ab6e8 100644 --- a/Source/Layout/ASStackLayoutSpec.mm +++ b/Source/Layout/ASStackLayoutSpec.mm @@ -160,7 +160,7 @@ - (ASLayout *)calculateLayoutThatFits:(ASSizeRange)constrainedSize self.style.descender = stackChildren.back().style.descender; } - NSMutableArray *sublayouts = [NSMutableArray array]; + auto sublayouts = [[NSMutableArray alloc] init]; for (const auto &item : positionedLayout.items) { [sublayouts addObject:item.layout]; } diff --git a/Source/Private/ASDisplayNode+AsyncDisplay.mm b/Source/Private/ASDisplayNode+AsyncDisplay.mm index 4d307439c..2cf772aec 100644 --- a/Source/Private/ASDisplayNode+AsyncDisplay.mm +++ b/Source/Private/ASDisplayNode+AsyncDisplay.mm @@ -208,7 +208,7 @@ - (asyncdisplaykit_async_transaction_operation_block_t)_displayBlockWithAsynchro if (shouldBeginRasterizing) { // Collect displayBlocks for all descendants. - NSMutableArray *displayBlocks = [NSMutableArray array]; + NSMutableArray *displayBlocks = [[NSMutableArray alloc] init]; [self _recursivelyRasterizeSelfAndSublayersWithIsCancelledBlock:isCancelledBlock displayBlocks:displayBlocks]; CHECK_CANCELLED_AND_RETURN_NIL(); diff --git a/Source/Private/ASMutableElementMap.m b/Source/Private/ASMutableElementMap.m index 1ddbc1272..2b5190213 100644 --- a/Source/Private/ASMutableElementMap.m +++ b/Source/Private/ASMutableElementMap.m @@ -87,7 +87,7 @@ - (void)removeSectionsOfItems:(NSIndexSet *)itemSections - (void)insertEmptySectionsOfItemsAtIndexes:(NSIndexSet *)sections { [sections enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) { - [_sectionsOfItems insertObject:[NSMutableArray array] atIndex:idx]; + [_sectionsOfItems insertObject:[[NSMutableArray alloc] init] atIndex:idx]; }]; } @@ -99,7 +99,7 @@ - (void)insertElement:(ASCollectionElement *)element atIndexPath:(NSIndexPath *) } else { NSMutableDictionary *supplementariesForKind = _supplementaryElements[kind]; if (supplementariesForKind == nil) { - supplementariesForKind = [NSMutableDictionary dictionary]; + supplementariesForKind = [[NSMutableDictionary alloc] init]; _supplementaryElements[kind] = supplementariesForKind; } supplementariesForKind[indexPath] = element; @@ -120,7 +120,7 @@ - (void)migrateSupplementaryElementsWithSectionMapping:(ASIntegerMap *)mapping // Note: it's tempting to update the dictionary in-place but because of the likely collision between old and new index paths, // subtle bugs are possible. Note that this process is rare (only on section-level updates), // that this work is done off-main, and that the typical supplementary element use case is just 1-per-section (header). - NSMutableDictionary *newSupps = [NSMutableDictionary dictionary]; + NSMutableDictionary *newSupps = [[NSMutableDictionary alloc] init]; [supps enumerateKeysAndObjectsUsingBlock:^(NSIndexPath * _Nonnull oldIndexPath, ASCollectionElement * _Nonnull obj, BOOL * _Nonnull stop) { NSInteger oldSection = oldIndexPath.section; NSInteger newSection = [mapping integerForKey:oldSection]; diff --git a/Source/Private/ASTwoDimensionalArrayUtils.m b/Source/Private/ASTwoDimensionalArrayUtils.m index 71a48d450..d1ce81360 100644 --- a/Source/Private/ASTwoDimensionalArrayUtils.m +++ b/Source/Private/ASTwoDimensionalArrayUtils.m @@ -71,7 +71,7 @@ void ASDeleteElementsInTwoDimensionalArrayAtIndexPaths(NSMutableArray *mutableAr NSArray *ASIndexPathsForTwoDimensionalArray(NSArray * twoDimensionalArray) { - NSMutableArray *result = [NSMutableArray array]; + NSMutableArray *result = [[NSMutableArray alloc] init]; NSInteger section = 0; NSInteger i = 0; for (NSArray *subarray in twoDimensionalArray) { @@ -87,7 +87,7 @@ void ASDeleteElementsInTwoDimensionalArrayAtIndexPaths(NSMutableArray *mutableAr NSArray *ASElementsInTwoDimensionalArray(NSArray * twoDimensionalArray) { - NSMutableArray *result = [NSMutableArray array]; + NSMutableArray *result = [[NSMutableArray alloc] init]; NSInteger i = 0; for (NSArray *subarray in twoDimensionalArray) { ASDisplayNodeCAssert([subarray isKindOfClass:[NSArray class]], @"This function expects NSArray *"); diff --git a/Source/Private/TextExperiment/Component/ASTextLayout.m b/Source/Private/TextExperiment/Component/ASTextLayout.m index 41e6718ce..2f475908b 100755 --- a/Source/Private/TextExperiment/Component/ASTextLayout.m +++ b/Source/Private/TextExperiment/Component/ASTextLayout.m @@ -473,7 +473,7 @@ + (ASTextLayout *)layoutWithContainer:(ASTextContainer *)container text:(NSAttri if (!cgPath) FAIL_AND_RETURN // frame setter config - frameAttrs = [NSMutableDictionary dictionary]; + frameAttrs = [[NSMutableDictionary alloc] init]; if (container.isPathFillEvenOdd == NO) { frameAttrs[(id)kCTFramePathFillRuleAttributeName] = @(kCTFramePathFillWindingNumber); } @@ -886,7 +886,7 @@ + (NSArray *)layoutWithContainers:(NSArray *)containers text:(NSAttributedString + (NSArray *)layoutWithContainers:(NSArray *)containers text:(NSAttributedString *)text range:(NSRange)range { if (!containers || !text) return nil; if (range.location + range.length > text.length) return nil; - NSMutableArray *layouts = [NSMutableArray array]; + NSMutableArray *layouts = [[NSMutableArray alloc] init]; for (NSUInteger i = 0, max = containers.count; i < max; i++) { ASTextContainer *container = containers[i]; ASTextLayout *layout = [self layoutWithContainer:container text:text range:range]; @@ -1959,7 +1959,7 @@ - (NSArray *)selectionRectsForRange:(ASTextRange *)range { range = [self _correctedRangeWithEdge:range]; BOOL isVertical = _container.verticalForm; - NSMutableArray *rects = [NSMutableArray array]; + NSMutableArray *rects = [[NSMutableArray alloc] init]; if (!range) return rects; NSUInteger startLineIndex = [self lineIndexForPosition:range.start]; diff --git a/Source/Private/_ASHierarchyChangeSet.mm b/Source/Private/_ASHierarchyChangeSet.mm index 67432a7c0..35d925fb0 100644 --- a/Source/Private/_ASHierarchyChangeSet.mm +++ b/Source/Private/_ASHierarchyChangeSet.mm @@ -237,7 +237,7 @@ - (NSArray *)itemChangesOfType:(_ASHierarchyChangeType)changeType - (NSIndexSet *)indexesForItemChangesOfType:(_ASHierarchyChangeType)changeType inSection:(NSUInteger)section { [self _ensureCompleted]; - NSMutableIndexSet *result = [NSMutableIndexSet indexSet]; + auto result = [[NSMutableIndexSet alloc] init]; for (_ASHierarchyItemChange *change in [self itemChangesOfType:changeType]) { [result addIndexes:[NSIndexSet as_indexSetFromIndexPaths:change.indexPaths inSection:section]]; } @@ -278,7 +278,7 @@ - (NSMutableArray *)itemMappings [self _ensureCompleted]; if (_itemMappings == nil) { - _itemMappings = [NSMutableArray array]; + _itemMappings = [[NSMutableArray alloc] init]; auto insertMap = [_ASHierarchyItemChange sectionToIndexSetMapFromChanges:_originalInsertItemChanges]; auto deleteMap = [_ASHierarchyItemChange sectionToIndexSetMapFromChanges:_originalDeleteItemChanges]; NSInteger oldSection = 0; @@ -302,7 +302,7 @@ - (NSMutableArray *)reverseItemMappings [self _ensureCompleted]; if (_reverseItemMappings == nil) { - _reverseItemMappings = [NSMutableArray array]; + _reverseItemMappings = [[NSMutableArray alloc] init]; for (NSInteger newSection = 0; newSection < _newItemCounts.size(); newSection++) { NSInteger oldSection = [self oldSectionForNewSection:newSection]; ASIntegerMap *table; @@ -751,7 +751,7 @@ + (void)sortAndCoalesceSectionChanges:(NSMutableArray<_ASHierarchySectionChange NSMutableArray *result = [[NSMutableArray alloc] init]; __block ASDataControllerAnimationOptions currentOptions = 0; - NSMutableIndexSet *currentIndexes = [NSMutableIndexSet indexSet]; + auto currentIndexes = [[NSMutableIndexSet alloc] init]; BOOL reverse = type == _ASHierarchyChangeTypeDelete || type == _ASHierarchyChangeTypeOriginalDelete; NSEnumerationOptions options = reverse ? NSEnumerationReverse : kNilOptions; @@ -790,7 +790,7 @@ + (void)sortAndCoalesceSectionChanges:(NSMutableArray<_ASHierarchySectionChange + (NSMutableIndexSet *)allIndexesInSectionChanges:(NSArray<_ASHierarchySectionChange *> *)changes { - NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; + auto indexes = [[NSMutableIndexSet alloc] init]; for (_ASHierarchySectionChange *change in changes) { [indexes addIndexes:change.indexSet]; } @@ -865,7 +865,7 @@ - (instancetype)initWithChangeType:(_ASHierarchyChangeType)changeType indexPaths // will become: {@0 : [0, 1], @2 : [5]} + (NSDictionary *)sectionToIndexSetMapFromChanges:(NSArray<_ASHierarchyItemChange *> *)changes { - NSMutableDictionary *sectionToIndexSetMap = [NSMutableDictionary dictionary]; + NSMutableDictionary *sectionToIndexSetMap = [[NSMutableDictionary alloc] init]; for (_ASHierarchyItemChange *change in changes) { for (NSIndexPath *indexPath in change.indexPaths) { NSNumber *sectionKey = @(indexPath.section); @@ -935,10 +935,10 @@ + (void)sortAndCoalesceItemChanges:(NSMutableArray<_ASHierarchyItemChange *> *)c [allIndexPaths sortUsingSelector:sorting]; // Create new changes by grouping sorted changes by animation option - NSMutableArray *result = [[NSMutableArray alloc] init]; + auto result = [[NSMutableArray<_ASHierarchyItemChange *> alloc] init]; ASDataControllerAnimationOptions currentOptions = 0; - NSMutableArray *currentIndexPaths = [NSMutableArray array]; + auto currentIndexPaths = [[NSMutableArray alloc] init]; for (NSIndexPath *indexPath in allIndexPaths) { ASDataControllerAnimationOptions options = [animationOptions[indexPath] integerValue]; diff --git a/Source/_ASTransitionContext.m b/Source/_ASTransitionContext.m index 15e549399..b796d7a72 100644 --- a/Source/_ASTransitionContext.m +++ b/Source/_ASTransitionContext.m @@ -33,8 +33,8 @@ @interface _ASTransitionContext () @implementation _ASTransitionContext - (instancetype)initWithAnimation:(BOOL)animated - layoutDelegate:(id<_ASTransitionContextLayoutDelegate>)layoutDelegate - completionDelegate:(id<_ASTransitionContextCompletionDelegate>)completionDelegate + layoutDelegate:(id<_ASTransitionContextLayoutDelegate>)layoutDelegate + completionDelegate:(id<_ASTransitionContextCompletionDelegate>)completionDelegate { self = [super init]; if (self) { @@ -69,7 +69,7 @@ - (CGRect)finalFrameForNode:(ASDisplayNode *)node - (NSArray *)subnodesForKey:(NSString *)key { - NSMutableArray *subnodes = [NSMutableArray array]; + NSMutableArray *subnodes = [[NSMutableArray alloc] init]; for (ASLayout *sublayout in [self layoutForKey:key].sublayouts) { [subnodes addObject:(ASDisplayNode *)sublayout.layoutElement]; }