Skip to content
Permalink
Browse files

Replace some legacy NSIndexSet enumeration with 10.6+ style -enumerat…

…eIndexesUsingBlock:
  • Loading branch information
dmoagx committed Mar 12, 2017
1 parent f5e022b commit 95250e0f0c5780ac113a9a4c948c452038b4c02a
@@ -1323,11 +1323,9 @@ - (NSDictionary*)shellEnvironmentForDocument:(NSString*)docUUID
if([firstResponder numberOfSelectedRows]) {
NSMutableArray *sel = [NSMutableArray array];
NSIndexSet *selectedRows = [firstResponder selectedRowIndexes];
NSUInteger rowIndex = [selectedRows firstIndex];
while ( rowIndex != NSNotFound ) {
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[sel addObject:[NSString stringWithFormat:@"%ld", (long)rowIndex]];
rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
}
}];
[env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices];
}

@@ -133,14 +133,10 @@ - (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes
NSMutableArray *subArray = [NSMutableArray arrayWithCapacity:[indexes count]];
NSUInteger count = [self count];

NSUInteger index = [indexes firstIndex];
while ( index != NSNotFound )
{
[indexes enumerateIndexesUsingBlock:^(NSUInteger index, BOOL * _Nonnull stop) {
if ( index < count )
[subArray addObject: [self objectAtIndex: index]];

index = [indexes indexGreaterThanIndex: index];
}
}];

return subArray;
}
@@ -875,14 +875,9 @@ - (NSArray *)selectedFavoriteNodes
NSMutableArray *nodes = [NSMutableArray array];
NSIndexSet *indexes = [favoritesOutlineView selectedRowIndexes];

NSUInteger currentIndex = [indexes firstIndex];

while (currentIndex != NSNotFound)
{
[indexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[nodes addObject:[favoritesOutlineView itemAtRow:currentIndex]];

currentIndex = [indexes indexGreaterThanIndex:currentIndex];
}
}];

return nodes;
}
@@ -1604,8 +1599,8 @@ - (void)_sortTreeNode:(SPTreeNode *)node usingKey:(NSString *)key
[self _sortTreeNode:treeNode usingKey:key];
}
}
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];
#warning What is this supposed to do? We create an empty indexset, iterate it (still empty) and release it again!?
NSMutableIndexSet *indexes = [[NSMutableIndexSet alloc] init];

NSUInteger i = [indexes lastIndex];

@@ -609,11 +609,9 @@ - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info

// TODO: still rely on a NSArray but in the future rewrite it to use the NSIndexSet directly
NSMutableArray *draggedRows = [[NSMutableArray alloc] initWithCapacity:1];
NSUInteger rowIndex = [draggedIndexes firstIndex];
while ( rowIndex != NSNotFound ) {
[draggedIndexes enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[draggedRows addObject:[NSNumber numberWithInteger:rowIndex]];
rowIndex = [draggedIndexes indexGreaterThanIndex: rowIndex];
}
}];


NSInteger destinationRow = row;
@@ -805,16 +803,9 @@ - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextIn
if (returnCode == NSAlertDefaultReturn) {
NSIndexSet *indexes = [contentFilterTableView selectedRowIndexes];

// Get last index
NSUInteger currentIndex = [indexes lastIndex];

while (currentIndex != NSNotFound)
{
[indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[contentFilters removeObjectAtIndex:currentIndex];

// Get next index (beginning from the end)
currentIndex = [indexes indexLessThanIndex:currentIndex];
}
}];

if ([contentFilters count] == 2) {
[contentFilterNameTextField setStringValue:@""];
@@ -168,30 +168,25 @@ - (NSString *)rowsAsTabStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[result appendString:@"\n"];
}

NSUInteger c;
id cellData = nil;

// Create an array of table column mappings for fast iteration
NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
for ( c = 0; c < numColumns; c++ )
columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
for (NSUInteger ci = 0; ci < numColumns; ci++ )
columnMappings[ci] = (NSUInteger)[[NSArrayObjectAtIndex(columns, ci) identifier] integerValue];

// Loop through the rows, adding their descriptive contents
NSUInteger rowIndex = [selectedRows firstIndex];
NSString *nullString = [prefs objectForKey:SPNullValue];
Class spmysqlGeometryData = [SPMySQLGeometryData class];
NSUInteger rowCounter = 0;
__block NSUInteger rowCounter = 0;

if((withBlobHandling == kBlobAsFile || withBlobHandling == kBlobAsImageFile) && tmpBlobFileDirectory && [tmpBlobFileDirectory length]) {
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:tmpBlobFileDirectory error:nil];
[fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}

while ( rowIndex != NSNotFound )
{
for ( c = 0; c < numColumns; c++ ) {
cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
for (NSUInteger c = 0; c < numColumns; c++ ) {
id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);

// Copy the shown representation of the cell - custom NULL display strings, (not loaded),
// definable representation of any blobs or binary texts.
@@ -262,10 +257,7 @@ - (NSString *)rowsAsTabStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
}
[result appendString:@"\n"];

// Select the next row index
rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
}
}];

// Remove the trailing line end
if ([result length]) {
@@ -306,31 +298,26 @@ - (NSString *)rowsAsCsvStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[result appendString:@"\n"];
}

NSUInteger c;
id cellData = nil;

// Create an array of table column mappings for fast iteration
NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
for ( c = 0; c < numColumns; c++ )
columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
for (NSUInteger ci = 0; ci < numColumns; ci++ )
columnMappings[ci] = (NSUInteger)[[NSArrayObjectAtIndex(columns, ci) identifier] integerValue];

// Loop through the rows, adding their descriptive contents
NSUInteger rowIndex = [selectedRows firstIndex];
NSString *nullString = [prefs objectForKey:SPNullValue];
Class spmysqlGeometryData = [SPMySQLGeometryData class];

NSUInteger rowCounter = 0;
__block NSUInteger rowCounter = 0;

if((withBlobHandling == kBlobAsFile || withBlobHandling == kBlobAsImageFile) && tmpBlobFileDirectory && [tmpBlobFileDirectory length]) {
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:tmpBlobFileDirectory error:nil];
[fm createDirectoryAtPath:tmpBlobFileDirectory withIntermediateDirectories:YES attributes:nil error:nil];
}

while ( rowIndex != NSNotFound )
{
for ( c = 0; c < numColumns; c++ ) {
cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
for (NSUInteger c = 0; c < numColumns; c++ ) {
id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);

// Copy the shown representation of the cell - custom NULL display strings, (not loaded),
// definable representation of any blobs or binary texts.
@@ -401,10 +388,7 @@ - (NSString *)rowsAsCsvStringWithHeaders:(BOOL)withHeaders onlySelectedRows:(BOO
[result deleteCharactersInRange:NSMakeRange([result length]-1, 1)];
}
[result appendString:@"\n"];

// Select the next row index
rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
}
}];

// Remove the trailing line end
if ([result length]) {
@@ -625,24 +609,20 @@ - (NSString *) draggedRowsAsTabString
NSIndexSet *selectedRows = [self selectedRowIndexes];

NSMutableString *result = [NSMutableString stringWithCapacity:2000];
NSUInteger c;
id cellData = nil;

// Create an array of table column mappings for fast iteration
NSUInteger *columnMappings = calloc(numColumns, sizeof(NSUInteger));
for ( c = 0; c < numColumns; c++ )
columnMappings[c] = (NSUInteger)[[NSArrayObjectAtIndex(columns, c) identifier] integerValue];
for (NSUInteger ci = 0; ci < numColumns; ci++ )
columnMappings[ci] = (NSUInteger)[[NSArrayObjectAtIndex(columns, ci) identifier] integerValue];

// Loop through the rows, adding their descriptive contents
NSUInteger rowIndex = [selectedRows firstIndex];
NSString *nullString = [prefs objectForKey:SPNullValue];
Class nsDataClass = [NSData class];
Class spmysqlGeometryData = [SPMySQLGeometryData class];
NSStringEncoding connectionEncoding = [mySQLConnection stringEncoding];
while ( rowIndex != NSNotFound )
{
for ( c = 0; c < numColumns; c++ ) {
cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
for (NSUInteger c = 0; c < numColumns; c++ ) {
id cellData = SPDataStorageObjectAtRowAndColumn(tableStorage, rowIndex, columnMappings[c]);

// Copy the shown representation of the cell - custom NULL display strings, (not loaded),
// and the string representation of any blobs or binary texts.
@@ -673,10 +653,7 @@ - (NSString *) draggedRowsAsTabString
}

[result appendString:@"\n"];

// Retrieve the next selected row index
rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
}
}];

// Trim the trailing line ending
if ([result length]) {
@@ -1307,11 +1284,9 @@ - (IBAction)executeBundleItemForDataTable:(id)sender
if([self numberOfSelectedRows]) {
NSMutableArray *sel = [NSMutableArray array];
NSIndexSet *selectedRows = [self selectedRowIndexes];
NSUInteger rowIndex = [selectedRows firstIndex];
while ( rowIndex != NSNotFound ) {
[selectedRows enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[sel addObject:[NSString stringWithFormat:@"%llu", (unsigned long long)rowIndex]];
rowIndex = [selectedRows indexGreaterThanIndex:rowIndex];
}
}];
[env setObject:[sel componentsJoinedByString:@"\t"] forKey:SPBundleShellVariableSelectedRowIndices];
}

@@ -992,14 +992,12 @@ - (IBAction)removeNewColumn:(id)sender
[toBeEditedRowIndexes removeIndex:toBeRemovedIndex];

// Renumber indexes greater than toBeRemovedIndex
NSInteger currentIndex = [toBeEditedRowIndexes firstIndex];
while(currentIndex != NSNotFound) {
if(currentIndex > toBeRemovedIndex) {
[toBeEditedRowIndexes enumerateIndexesUsingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
if(currentIndex > (NSUInteger)toBeRemovedIndex) {
[toBeEditedRowIndexes addIndex:currentIndex-1];
[toBeEditedRowIndexes removeIndex:currentIndex];
}
currentIndex = [toBeEditedRowIndexes indexGreaterThanIndex:currentIndex];
}
}];

[self _setupFieldMappingPopUpMenus];
[fieldMapperTableView reloadData];
@@ -1155,15 +1153,10 @@ - (IBAction)removeGlobalValue:(id)sender

NSIndexSet *indexes = [globalValuesTableView selectedRowIndexes];

// get last index
NSUInteger currentIndex = [indexes lastIndex];

while (currentIndex != NSNotFound) {
[indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[fieldMappingGlobalValues removeObjectAtIndex:currentIndex+numberOfImportColumns];
[fieldMappingGlobalValuesSQLMarked removeObjectAtIndex:currentIndex+numberOfImportColumns];
// get next index (beginning from the end)
currentIndex = [indexes indexLessThanIndex:currentIndex];
}
}];

[globalValuesTableView reloadData];

@@ -140,10 +140,7 @@ - (IBAction)copy:(id)sender
NSMutableString *string = [NSMutableString string];
NSIndexSet *rows = [processListTableView selectedRowIndexes];

NSUInteger i = [rows firstIndex];

while (i != NSNotFound)
{
[rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
if (i < [processesFiltered count]) {
NSDictionary *process = NSArrayObjectAtIndex(processesFiltered, i);

@@ -160,9 +157,7 @@ - (IBAction)copy:(id)sender
[string appendString:stringTmp];
[string appendString:@"\n"];
}

i = [rows indexGreaterThanIndex:i];
}
}];

NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];

@@ -158,16 +158,13 @@ - (void)copy:(id)sender
NSMutableString *string = [NSMutableString string];
NSIndexSet *rows = [consoleTableView selectedRowIndexes];

NSUInteger i = [rows firstIndex];

BOOL includeTimestamps = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDateColumnID] isHidden];
BOOL includeConnections = ![[consoleTableView tableColumnWithIdentifier:SPTableViewConnectionColumnID] isHidden];
BOOL includeDatabases = ![[consoleTableView tableColumnWithIdentifier:SPTableViewDatabaseColumnID] isHidden];

[string setString:@""];

while (i != NSNotFound)
{
[rows enumerateIndexesUsingBlock:^(NSUInteger i, BOOL * _Nonnull stop) {
if (i < [messagesVisibleSet count]) {
SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i);

@@ -195,9 +192,7 @@ - (void)copy:(id)sender

[string appendFormat:@"%@\n", [message message]];
}

i = [rows indexGreaterThanIndex:i];
}
}];

NSPasteboard *pasteBoard = [NSPasteboard generalPasteboard];

@@ -730,11 +730,9 @@ - (BOOL)tableView:(NSTableView *)tableView acceptDrop:(id <NSDraggingInfo>)info

// TODO: still rely on a NSArray but in the future rewrite it to use the NSIndexSet directly
NSMutableArray *draggedRows = [[NSMutableArray alloc] initWithCapacity:1];
NSUInteger rowIndex = [draggedIndexes firstIndex];
while ( rowIndex != NSNotFound ) {
[draggedIndexes enumerateIndexesUsingBlock:^(NSUInteger rowIndex, BOOL * _Nonnull stop) {
[draggedRows addObject:[NSNumber numberWithUnsignedInteger:rowIndex]];
rowIndex = [draggedIndexes indexGreaterThanIndex: rowIndex];
}
}];

NSInteger destinationRow = row;
NSInteger offset = 0;
@@ -791,14 +789,9 @@ - (void)sheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextIn
if (returnCode == NSAlertDefaultReturn) {
NSIndexSet *indexes = [favoritesTableView selectedRowIndexes];

// get last index
NSUInteger currentIndex = [indexes lastIndex];

while (currentIndex != NSNotFound) {
[indexes enumerateIndexesWithOptions:NSEnumerationReverse usingBlock:^(NSUInteger currentIndex, BOOL * _Nonnull stop) {
[favorites removeObjectAtIndex:currentIndex];
// get next index (beginning from the end)
currentIndex = [indexes indexLessThanIndex:currentIndex];
}
}];

[favoritesArrayController rearrangeObjects];
[favoritesTableView reloadData];

0 comments on commit 95250e0

Please sign in to comment.
You can’t perform that action at this time.