From 502dc33d7d8dd22ac189e234d02b02a3979f6348 Mon Sep 17 00:00:00 2001 From: Bofei Zhu Date: Sat, 21 Jan 2017 23:57:58 -0500 Subject: [PATCH] Convert NSUInteger to NSInteger --- Source/Common/IGListBatchUpdateData.mm | 14 +++++------ Source/Common/IGListIndexPathResult.m | 2 +- Source/Common/IGListIndexSetResult.m | 2 +- Source/IGListAdapter.m | 18 +++++++------- Source/IGListAdapterUpdater.m | 4 ++-- Source/IGListStackedSectionController.m | 32 ++++++++++++------------- Source/Internal/IGListDisplayHandler.m | 2 +- Source/Internal/IGListSectionMap.m | 4 ++-- Tests/IGListBatchUpdateDataTests.m | 6 ++--- Tests/IGListDiffTests.m | 8 +++---- 10 files changed, 46 insertions(+), 46 deletions(-) diff --git a/Source/Common/IGListBatchUpdateData.mm b/Source/Common/IGListBatchUpdateData.mm index d8a974aa1..b9d983f7d 100644 --- a/Source/Common/IGListBatchUpdateData.mm +++ b/Source/Common/IGListBatchUpdateData.mm @@ -18,7 +18,7 @@ static NSMutableSet *indexPathsMinusSections(NSSet *indexPaths, NSIndexSet *sections) { NSMutableSet *filteredIndexPaths = [indexPaths mutableCopy]; for (NSIndexPath *indexPath in indexPaths) { - const NSUInteger section = indexPath.section; + const NSInteger section = indexPath.section; if ([sections containsIndex:section]) { [filteredIndexPaths removeObject:indexPath]; } @@ -42,7 +42,7 @@ static void convertMoveToDeleteAndInsert(NSMutableSet *moves, @implementation IGListBatchUpdateData // Converts all section moves that have index path operations into a section delete + insert. -+ (void)cleanIndexPathsWithMap:(const std::unordered_map &)map ++ (void)cleanIndexPathsWithMap:(const std::unordered_map &)map moves:(NSMutableSet *)moves indexPaths:(NSMutableSet *)indexPaths deletes:(NSMutableIndexSet *)deletes @@ -81,12 +81,12 @@ - (instancetype)initWithInsertSections:(NSIndexSet *)insertSections // changes (e.g. a moved section that has a delete + reload on different index paths w/in the section) will only // convert one of the item changes into a section delete+insert. this will fail hard and be VERY difficult to // debug - const NSUInteger moveCount = [moveSections count]; - std::unordered_map fromMap(moveCount); - std::unordered_map toMap(moveCount); + const NSInteger moveCount = [moveSections count]; + std::unordered_map fromMap(moveCount); + std::unordered_map toMap(moveCount); for (IGListMoveIndex *move in moveSections) { - const NSUInteger from = move.from; - const NSUInteger to = move.to; + const NSInteger from = move.from; + const NSInteger to = move.to; // if the move is already deleted or inserted, discard it and use delete+insert instead if ([deleteSections containsIndex:from] || [insertSections containsIndex:to]) { diff --git a/Source/Common/IGListIndexPathResult.m b/Source/Common/IGListIndexPathResult.m index d8e9705a6..bbc1750d2 100644 --- a/Source/Common/IGListIndexPathResult.m +++ b/Source/Common/IGListIndexPathResult.m @@ -45,7 +45,7 @@ - (IGListIndexPathResult *)resultForBatchUpdates { NSMutableArray *filteredMoves = [moves mutableCopy]; // convert move+update to delete+insert, respecting the from/to of the move - const NSUInteger moveCount = moves.count; + const NSInteger moveCount = moves.count; for (NSInteger i = moveCount - 1; i >= 0; i--) { IGListMoveIndexPath *move = moves[i]; if ([filteredUpdates containsObject:move.from]) { diff --git a/Source/Common/IGListIndexSetResult.m b/Source/Common/IGListIndexSetResult.m index 458a823d8..ccc02d5fb 100644 --- a/Source/Common/IGListIndexSetResult.m +++ b/Source/Common/IGListIndexSetResult.m @@ -47,7 +47,7 @@ - (IGListIndexSetResult *)resultForBatchUpdates { NSMutableArray *filteredMoves = [moves mutableCopy]; // convert all update+move to delete+insert - const NSUInteger moveCount = moves.count; + const NSInteger moveCount = moves.count; for (NSInteger i = moveCount - 1; i >= 0; i--) { IGListMoveIndex *move = moves[i]; if ([filteredUpdates containsIndex:move.from]) { diff --git a/Source/IGListAdapter.m b/Source/IGListAdapter.m index ad574a8fc..cb5f100b7 100644 --- a/Source/IGListAdapter.m +++ b/Source/IGListAdapter.m @@ -147,13 +147,13 @@ - (void)scrollToObject:(id)object IGAssertMainThread(); IGParameterAssert(object != nil); - const NSUInteger section = [self sectionForObject:object]; + const NSInteger section = [self sectionForObject:object]; if (section == NSNotFound) { return; } UICollectionView *collectionView = self.collectionView; - const NSUInteger numberOfItems = [collectionView numberOfItemsInSection:section]; + const NSInteger numberOfItems = [collectionView numberOfItemsInSection:section]; if (numberOfItems == 0) { return; } @@ -353,7 +353,7 @@ - (id)objectForSectionController:(IGListSectionController *) IGAssertMainThread(); IGParameterAssert(sectionController != nil); - const NSUInteger section = [self.sectionMap sectionForSectionController:sectionController]; + const NSInteger section = [self.sectionMap sectionForSectionController:sectionController]; return [self.sectionMap objectForSection:section]; } @@ -403,7 +403,7 @@ - (NSArray *)visibleObjects { IGListSectionController *sectionController = [self sectionControllerForCell:cell]; IGAssert(sectionController != nil, @"Section controller nil for cell %@", cell); if (sectionController != nil) { - const NSUInteger section = [self sectionForSectionController:sectionController]; + const NSInteger section = [self sectionForSectionController:sectionController]; id object = [self objectAtSection:section]; IGAssert(object != nil, @"Object not found for section controller %@ at section %zi", sectionController, section); if (object != nil) { @@ -481,7 +481,7 @@ - (void)updateObjects:(NSArray *)objects dataSource:(id sectionController.isLastSection = (object == lastObject); // check if the item has changed instances or is new - const NSUInteger oldSection = [map sectionForObject:object]; + const NSInteger oldSection = [map sectionForObject:object]; if (oldSection == NSNotFound || [map objectForSection:oldSection] != object) { [updatedObjects addObject:object]; } @@ -499,7 +499,7 @@ - (void)updateObjects:(NSArray *)objects dataSource:(id [[map sectionControllerForObject:object] didUpdateToObject:object]; } - NSUInteger itemCount = 0; + NSInteger itemCount = 0; for (IGListSectionController *sectionController in sectionControllers) { itemCount += [sectionController numberOfItems]; } @@ -549,7 +549,7 @@ - (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)adjustForUpdateBlock IGListSectionMap *map = [self sectionMapAdjustForUpdateBlock:adjustForUpdateBlock]; - const NSUInteger section = [map sectionForSectionController:sectionController]; + const NSInteger section = [map sectionForSectionController:sectionController]; if (section != NSNotFound) { [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [indexPaths addObject:[NSIndexPath indexPathForItem:idx inSection:section]]; @@ -559,7 +559,7 @@ - (IGListSectionMap *)sectionMapAdjustForUpdateBlock:(BOOL)adjustForUpdateBlock } - (NSIndexPath *)indexPathForSectionController:(IGListSectionController *)controller index:(NSInteger)index { - const NSUInteger section = [self.sectionMap sectionForSectionController:controller]; + const NSInteger section = [self.sectionMap sectionForSectionController:controller]; if (section == NSNotFound) { return nil; } else { @@ -778,7 +778,7 @@ - (__kindof UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index NSMutableArray *cells = [NSMutableArray new]; UICollectionView *collectionView = self.collectionView; NSArray *visibleCells = [collectionView visibleCells]; - const NSUInteger section = [self sectionForSectionController:sectionController]; + const NSInteger section = [self sectionForSectionController:sectionController]; for (UICollectionViewCell *cell in visibleCells) { if ([collectionView indexPathForCell:cell].section == section) { [cells addObject:cell]; diff --git a/Source/IGListAdapterUpdater.m b/Source/IGListAdapterUpdater.m index 4dd537233..0aca7845d 100644 --- a/Source/IGListAdapterUpdater.m +++ b/Source/IGListAdapterUpdater.m @@ -231,8 +231,8 @@ void convertReloadToDeleteInsert(NSMutableIndexSet *reloads, [[reloads copy] enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { // if a diff was not performed, there are no changes. instead use the same index that was originally queued id diffIdentifier = hasObjects ? [fromObjects[idx] diffIdentifier] : nil; - const NSUInteger from = hasObjects ? [result oldIndexForIdentifier:diffIdentifier] : idx; - const NSUInteger to = hasObjects ? [result newIndexForIdentifier:diffIdentifier] : idx; + const NSInteger from = hasObjects ? [result oldIndexForIdentifier:diffIdentifier] : idx; + const NSInteger to = hasObjects ? [result newIndexForIdentifier:diffIdentifier] : idx; [reloads removeIndex:from]; // if a reload is queued outside the diff and the object was inserted or deleted it cannot be diff --git a/Source/IGListStackedSectionController.m b/Source/IGListStackedSectionController.m index 1496998fb..f8d7937df 100644 --- a/Source/IGListStackedSectionController.m +++ b/Source/IGListStackedSectionController.m @@ -68,12 +68,12 @@ - (void)reloadData { NSMutableArray *sectionControllers = [[NSMutableArray alloc] init]; NSMutableArray *offsets = [[NSMutableArray alloc] init]; - NSUInteger numberOfItems = 0; + NSInteger numberOfItems = 0; for (IGListSectionController *sectionController in self.sectionControllers) { [offsets addObject:@(numberOfItems)]; - const NSUInteger items = [sectionController numberOfItems]; - for (NSUInteger i = 0; i < items; i++) { + const NSInteger items = [sectionController numberOfItems]; + for (NSInteger i = 0; i < items; i++) { [sectionControllers addObject:sectionController]; } @@ -93,24 +93,24 @@ - (void)reloadData { } - (NSInteger)offsetForSectionController:(IGListSectionController *)sectionController { - const NSUInteger index = [self.sectionControllers indexOfObject:sectionController]; + const NSInteger index = [self.sectionControllers indexOfObject:sectionController]; IGAssert(index != NSNotFound, @"Querying offset for an undocumented section controller"); return [self.sectionControllerOffsets[index] integerValue]; } - (NSInteger)localIndexForSectionController:(IGListSectionController *)sectionController index:(NSInteger)index { - const NSUInteger offset = [self offsetForSectionController:sectionController]; + const NSInteger offset = [self offsetForSectionController:sectionController]; IGAssert(offset <= index, @"Section controller offset must be less than or equal to the item index"); return index - offset; } - (NSInteger)relativeIndexForSectionController:(IGListSectionController *)sectionController fromLocalIndex:(NSInteger)index { - const NSUInteger offset = [self offsetForSectionController:sectionController]; + const NSInteger offset = [self offsetForSectionController:sectionController]; return index + offset; } - (NSIndexSet *)itemIndexesForSectionController:(IGListSectionController *)sectionController indexes:(NSIndexSet *)indexes { - const NSUInteger offset = [self offsetForSectionController:sectionController]; + const NSInteger offset = [self offsetForSectionController:sectionController]; NSMutableIndexSet *itemIndexes = [[NSMutableIndexSet alloc] init]; [indexes enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL *stop) { [itemIndexes addIndex:(idx + offset)]; @@ -136,13 +136,13 @@ - (NSInteger)numberOfItems { - (CGSize)sizeForItemAtIndex:(NSInteger)index { IGListSectionController *sectionController = [self sectionControllerForObjectIndex:index]; - const NSUInteger localIndex = [self localIndexForSectionController:sectionController index:index]; + const NSInteger localIndex = [self localIndexForSectionController:sectionController index:index]; return [sectionController sizeForItemAtIndex:localIndex]; } - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index { IGListSectionController *sectionController = [self sectionControllerForObjectIndex:index]; - const NSUInteger localIndex = [self localIndexForSectionController:sectionController index:index]; + const NSInteger localIndex = [self localIndexForSectionController:sectionController index:index]; return [sectionController cellForItemAtIndex:localIndex]; } @@ -155,7 +155,7 @@ - (void)didUpdateToObject:(id)object { - (void)didSelectItemAtIndex:(NSInteger)index { IGListSectionController *sectionController = [self sectionControllerForObjectIndex:index]; - const NSUInteger localIndex = [self localIndexForSectionController:sectionController index:index]; + const NSInteger localIndex = [self localIndexForSectionController:sectionController index:index]; [sectionController didSelectItemAtIndex:localIndex]; } @@ -166,7 +166,7 @@ - (CGSize)containerSize { } - (NSInteger)indexForCell:(UICollectionViewCell *)cell sectionController:(IGListSectionController *)sectionController { - const NSUInteger index = [self.collectionContext indexForCell:cell sectionController:self]; + const NSInteger index = [self.collectionContext indexForCell:cell sectionController:self]; return [self localIndexForSectionController:sectionController index:index]; } @@ -179,7 +179,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController: id collectionContext = self.collectionContext; NSArray *visibleCells = [collectionContext visibleCellsForSectionController:self]; for (UICollectionViewCell *cell in visibleCells) { - const NSUInteger index = [collectionContext indexForCell:cell sectionController:self]; + const NSInteger index = [collectionContext indexForCell:cell sectionController:self]; if (self.sectionControllersForItems[index] == sectionController) { [cells addObject:cell]; } @@ -188,7 +188,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController: } - (void)deselectItemAtIndex:(NSInteger)index sectionController:(IGListSectionController *)sectionController animated:(BOOL)animated { - const NSUInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index]; + const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index]; [self.collectionContext deselectItemAtIndex:offsetIndex sectionController:self animated:animated]; } @@ -297,7 +297,7 @@ - (void)scrollToSectionController:(IGListSectionController *) atIndex:(NSInteger)index scrollPosition:(UICollectionViewScrollPosition)scrollPosition animated:(BOOL)animated { - const NSUInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index]; + const NSInteger offsetIndex = [self relativeIndexForSectionController:sectionController fromLocalIndex:index]; [self.collectionContext scrollToSectionController:self atIndex:offsetIndex scrollPosition:scrollPosition @@ -308,7 +308,7 @@ - (void)scrollToSectionController:(IGListSectionController *) - (void)listAdapter:(IGListAdapter *)listAdapter willDisplaySectionController:(IGListSectionController *)sectionController cell:(UICollectionViewCell *)cell atIndex:(NSInteger)index { IGListSectionController *childSectionController = [self sectionControllerForObjectIndex:index]; - const NSUInteger localIndex = [self localIndexForSectionController:childSectionController index:index]; + const NSInteger localIndex = [self localIndexForSectionController:childSectionController index:index]; // update the assoc objects for use in didEndDisplay [cell ig_setStackedSectionController:childSectionController]; @@ -326,7 +326,7 @@ - (void)listAdapter:(IGListAdapter *)listAdapter willDisplaySectionController:(I } - (void)listAdapter:(IGListAdapter *)listAdapter didEndDisplayingSectionController:(IGListSectionController *)sectionController cell:(UICollectionViewCell *)cell atIndex:(NSInteger)index { - const NSUInteger localIndex = [cell ig_stackedSectionControllerIndex]; + const NSInteger localIndex = [cell ig_stackedSectionControllerIndex]; IGListSectionController *childSectionController = [cell ig_stackedSectionController]; NSCountedSet *visibleSectionControllers = self.visibleSectionControllers; diff --git a/Source/Internal/IGListDisplayHandler.m b/Source/Internal/IGListDisplayHandler.m index 6d106b618..20cdec820 100644 --- a/Source/Internal/IGListDisplayHandler.m +++ b/Source/Internal/IGListDisplayHandler.m @@ -62,7 +62,7 @@ - (void)didEndDisplayingCell:(UICollectionViewCell *)cell IGParameterAssert(listAdapter != nil); IGParameterAssert(indexPath != nil); - const NSUInteger section = indexPath.section; + const NSInteger section = indexPath.section; NSMapTable *cellObjectMap = self.visibleCellObjectMap; id object = [cellObjectMap objectForKey:cell]; diff --git a/Source/Internal/IGListSectionMap.m b/Source/Internal/IGListSectionMap.m index b0d2a1b13..a1acdf7ef 100644 --- a/Source/Internal/IGListSectionMap.m +++ b/Source/Internal/IGListSectionMap.m @@ -101,7 +101,7 @@ - (void)reset { - (void)updateObject:(id)object { IGParameterAssert(object != nil); - const NSUInteger section = [self sectionForObject:object]; + const NSInteger section = [self sectionForObject:object]; id sectionController = [self sectionControllerForObject:object]; [self.sectionControllerToSectionMap setObject:@(section) forKey:sectionController]; [self.sectionControllerToObjectMap setObject:sectionController forKey:object]; @@ -116,7 +116,7 @@ - (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController *sectionController = [self sectionControllerForObject:object]; block(object, sectionController, section, &stop); diff --git a/Tests/IGListBatchUpdateDataTests.m b/Tests/IGListBatchUpdateDataTests.m index 6f973a366..5166f70f4 100644 --- a/Tests/IGListBatchUpdateDataTests.m +++ b/Tests/IGListBatchUpdateDataTests.m @@ -13,7 +13,7 @@ // IGListMoveIndexInternal.h @interface IGListMoveIndex (Private) -- (instancetype)initWithFrom:(NSUInteger)from to:(NSUInteger)to; +- (instancetype)initWithFrom:(NSInteger)from to:(NSInteger)to; @end @interface IGListBatchUpdateDataTests : XCTestCase @@ -30,11 +30,11 @@ @implementation IGListBatchUpdateDataTests return set; } -static NSIndexPath *newPath(NSUInteger section, NSUInteger item) { +static NSIndexPath *newPath(NSInteger section, NSInteger item) { return [NSIndexPath indexPathForItem:item inSection:section]; } -static IGListMoveIndex *newMove(NSUInteger from, NSUInteger to) { +static IGListMoveIndex *newMove(NSInteger from, NSInteger to) { return [[IGListMoveIndex alloc] initWithFrom:from to:to]; } diff --git a/Tests/IGListDiffTests.m b/Tests/IGListDiffTests.m index 88aa7e254..cd567c6db 100644 --- a/Tests/IGListDiffTests.m +++ b/Tests/IGListDiffTests.m @@ -43,22 +43,22 @@ @interface IGListIndexSetResult (UnitTests) -- (NSUInteger)changeCount; +- (NSInteger)changeCount; @end @implementation IGListIndexSetResult (UnitTests) -- (NSUInteger)changeCount { +- (NSInteger)changeCount { return self.inserts.count + self.deletes.count + self.moves.count + self.updates.count; } @end @interface IGListIndexPathResult (UnitTests) -- (NSUInteger)changeCount; +- (NSInteger)changeCount; @end @implementation IGListIndexPathResult (UnitTests) -- (NSUInteger)changeCount { +- (NSInteger)changeCount { return self.inserts.count + self.deletes.count + self.moves.count + self.updates.count; } @end