Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert NSUInteger to NSInteger #440

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Source/Common/IGListBatchUpdateData.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
static NSMutableSet *indexPathsMinusSections(NSSet<NSIndexPath *> *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];
}
Expand All @@ -42,7 +42,7 @@ static void convertMoveToDeleteAndInsert(NSMutableSet<IGListMoveIndex *> *moves,
@implementation IGListBatchUpdateData

// Converts all section moves that have index path operations into a section delete + insert.
+ (void)cleanIndexPathsWithMap:(const std::unordered_map<NSUInteger, IGListMoveIndex*> &)map
+ (void)cleanIndexPathsWithMap:(const std::unordered_map<NSInteger, IGListMoveIndex*> &)map
moves:(NSMutableSet<IGListMoveIndex *> *)moves
indexPaths:(NSMutableSet<NSIndexPath *> *)indexPaths
deletes:(NSMutableIndexSet *)deletes
Expand Down Expand Up @@ -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<NSUInteger, IGListMoveIndex*> fromMap(moveCount);
std::unordered_map<NSUInteger, IGListMoveIndex*> toMap(moveCount);
const NSInteger moveCount = [moveSections count];
std::unordered_map<NSInteger, IGListMoveIndex*> fromMap(moveCount);
std::unordered_map<NSInteger, IGListMoveIndex*> 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]) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/IGListIndexPathResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ - (IGListIndexPathResult *)resultForBatchUpdates {
NSMutableArray<IGListMoveIndexPath *> *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]) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/IGListIndexSetResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ - (IGListIndexSetResult *)resultForBatchUpdates {
NSMutableArray<IGListMoveIndex *> *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]) {
Expand Down
18 changes: 9 additions & 9 deletions Source/IGListAdapter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -353,7 +353,7 @@ - (id)objectForSectionController:(IGListSectionController <IGListSectionType> *)
IGAssertMainThread();
IGParameterAssert(sectionController != nil);

const NSUInteger section = [self.sectionMap sectionForSectionController:sectionController];
const NSInteger section = [self.sectionMap sectionForSectionController:sectionController];
return [self.sectionMap objectForSection:section];
}

Expand Down Expand Up @@ -403,7 +403,7 @@ - (NSArray *)visibleObjects {
IGListSectionController<IGListSectionType> *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) {
Expand Down Expand Up @@ -481,7 +481,7 @@ - (void)updateObjects:(NSArray *)objects dataSource:(id<IGListAdapterDataSource>
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];
}
Expand All @@ -499,7 +499,7 @@ - (void)updateObjects:(NSArray *)objects dataSource:(id<IGListAdapterDataSource>
[[map sectionControllerForObject:object] didUpdateToObject:object];
}

NSUInteger itemCount = 0;
NSInteger itemCount = 0;
for (IGListSectionController<IGListSectionType> *sectionController in sectionControllers) {
itemCount += [sectionController numberOfItems];
}
Expand Down Expand Up @@ -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]];
Expand All @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions Source/IGListAdapterUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -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<NSObject> 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
Expand Down
32 changes: 16 additions & 16 deletions Source/IGListStackedSectionController.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ - (void)reloadData {
NSMutableArray *sectionControllers = [[NSMutableArray alloc] init];
NSMutableArray *offsets = [[NSMutableArray alloc] init];

NSUInteger numberOfItems = 0;
NSInteger numberOfItems = 0;
for (IGListSectionController<IGListSectionType> *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];
}

Expand All @@ -93,24 +93,24 @@ - (void)reloadData {
}

- (NSInteger)offsetForSectionController:(IGListSectionController<IGListSectionType> *)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<IGListSectionType> *)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<IGListSectionType> *)sectionController fromLocalIndex:(NSInteger)index {
const NSUInteger offset = [self offsetForSectionController:sectionController];
const NSInteger offset = [self offsetForSectionController:sectionController];
return index + offset;
}

- (NSIndexSet *)itemIndexesForSectionController:(IGListSectionController<IGListSectionType> *)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)];
Expand All @@ -136,13 +136,13 @@ - (NSInteger)numberOfItems {

- (CGSize)sizeForItemAtIndex:(NSInteger)index {
IGListSectionController<IGListSectionType> *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<IGListSectionType> *sectionController = [self sectionControllerForObjectIndex:index];
const NSUInteger localIndex = [self localIndexForSectionController:sectionController index:index];
const NSInteger localIndex = [self localIndexForSectionController:sectionController index:index];
return [sectionController cellForItemAtIndex:localIndex];
}

Expand All @@ -155,7 +155,7 @@ - (void)didUpdateToObject:(id)object {

- (void)didSelectItemAtIndex:(NSInteger)index {
IGListSectionController<IGListSectionType> *sectionController = [self sectionControllerForObjectIndex:index];
const NSUInteger localIndex = [self localIndexForSectionController:sectionController index:index];
const NSInteger localIndex = [self localIndexForSectionController:sectionController index:index];
[sectionController didSelectItemAtIndex:localIndex];
}

Expand All @@ -166,7 +166,7 @@ - (CGSize)containerSize {
}

- (NSInteger)indexForCell:(UICollectionViewCell *)cell sectionController:(IGListSectionController<IGListSectionType> *)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];
}

Expand All @@ -179,7 +179,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:
id<IGListCollectionContext> 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];
}
Expand All @@ -188,7 +188,7 @@ - (UICollectionViewCell *)cellForItemAtIndex:(NSInteger)index sectionController:
}

- (void)deselectItemAtIndex:(NSInteger)index sectionController:(IGListSectionController<IGListSectionType> *)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];
}

Expand Down Expand Up @@ -297,7 +297,7 @@ - (void)scrollToSectionController:(IGListSectionController<IGListSectionType> *)
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
Expand All @@ -308,7 +308,7 @@ - (void)scrollToSectionController:(IGListSectionController<IGListSectionType> *)

- (void)listAdapter:(IGListAdapter *)listAdapter willDisplaySectionController:(IGListSectionController<IGListSectionType> *)sectionController cell:(UICollectionViewCell *)cell atIndex:(NSInteger)index {
IGListSectionController<IGListSectionType> *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];
Expand All @@ -326,7 +326,7 @@ - (void)listAdapter:(IGListAdapter *)listAdapter willDisplaySectionController:(I
}

- (void)listAdapter:(IGListAdapter *)listAdapter didEndDisplayingSectionController:(IGListSectionController<IGListSectionType> *)sectionController cell:(UICollectionViewCell *)cell atIndex:(NSInteger)index {
const NSUInteger localIndex = [cell ig_stackedSectionControllerIndex];
const NSInteger localIndex = [cell ig_stackedSectionControllerIndex];
IGListSectionController<IGListSectionType> *childSectionController = [cell ig_stackedSectionController];

NSCountedSet *visibleSectionControllers = self.visibleSectionControllers;
Expand Down
2 changes: 1 addition & 1 deletion Source/Internal/IGListDisplayHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions Source/Internal/IGListSectionMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -116,7 +116,7 @@ - (void)enumerateUsingBlock:(void (^)(id object, IGListSectionController <IGList

BOOL stop = NO;
NSArray *objects = self.objects;
for (NSUInteger section = 0; section < objects.count; section++) {
for (NSInteger section = 0; section < objects.count; section++) {
id object = objects[section];
IGListSectionController <IGListSectionType> *sectionController = [self sectionControllerForObject:object];
block(object, sectionController, section, &stop);
Expand Down
6 changes: 3 additions & 3 deletions Tests/IGListBatchUpdateDataTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/IGListDiffTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down