From 515e93007d444c33ca82f7c43b76cf8c228cb9d6 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 18 Jun 2009 21:34:51 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20to=20SPArrayAdditions.h:=20NSArrayO?= =?UTF-8?q?bjectAtIndex()=20inline=20function=20-=20id=20o=20=3D=20NSArray?= =?UTF-8?q?ObjectAtIndex(anArray,=20index)=20:=3D=3D=20id=20o=20=3D=20[anA?= =?UTF-8?q?rray=20objectAtIndex:index]=20-=20this=20speed=20up=20it=20~3?= =?UTF-8?q?=C2=B5s=20per=20call=20-=20replaced=20that=20inline=20function?= =?UTF-8?q?=20for=20such=20calls=20within=20loops=20to=20speed=20up=20them?= =?UTF-8?q?=20=E2=80=A2=20used=20IMP=20function=20pointers=20for=20keepAli?= =?UTF-8?q?ve=20calls=20within=20queryString:=20=E2=80=A2=20set=20-O3=20(F?= =?UTF-8?q?astest)=20compiler=20option=20=E2=80=A2=20allow=20in=20preferen?= =?UTF-8?q?ce=20pane=20"Tables"=20to=20set=20the=20Limit=20up=20to=2050000?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/Preferences.xib | 111 ++++++------------------------- Source/CMCopyTable.m | 4 +- Source/CMMCPConnection.h | 6 ++ Source/CMMCPConnection.m | 26 +++++--- Source/CMMCPResult.m | 3 +- Source/CMTextView.m | 11 +-- Source/CustomQuery.m | 21 +++--- Source/NoodleLineNumberView.m | 7 +- Source/SPArrayAdditions.h | 9 +++ Source/SPExportController.m | 7 +- Source/SPNarrowDownCompletion.m | 5 +- Source/SPQueryConsole.m | 3 +- Source/SPTableData.m | 54 ++++++++------- Source/TableContent.m | 42 ++++++------ Source/TableDocument.m | 5 +- Source/TableDump.m | 69 ++++++++++--------- Source/TablesList.m | 17 ++--- sequel-pro.xcodeproj/project.pbxproj | 2 +- 18 files changed, 187 insertions(+), 215 deletions(-) diff --git a/Interfaces/English.lproj/Preferences.xib b/Interfaces/English.lproj/Preferences.xib index 1f40515d..3dcce06a 100644 --- a/Interfaces/English.lproj/Preferences.xib +++ b/Interfaces/English.lproj/Preferences.xib @@ -8,7 +8,7 @@ 353.00 YES - + YES @@ -53,7 +53,7 @@ {3.40282e+38, 3.40282e+38} - + 268 YES @@ -62,7 +62,6 @@ 268 {{151, 121}, {254, 26}} - YES -2076049856 @@ -390,7 +389,6 @@ 268 {{152, 168}, {209, 18}} - YES 67239424 @@ -418,7 +416,6 @@ 268 {{40, 196}, {108, 17}} - YES 67239488 @@ -451,7 +448,6 @@ 268 {{151, 190}, {254, 26}} - YES -2076049856 @@ -484,7 +480,6 @@ 268 {{33, 127}, {116, 17}} - YES 67239424 @@ -501,7 +496,6 @@ 268 {{152, 84}, {166, 18}} - YES 67239424 @@ -524,7 +518,6 @@ 268 {{152, 62}, {254, 18}} - YES 67239424 @@ -547,7 +540,6 @@ 12 {{154, 156}, {326, 5}} - {0, 0} 67239424 @@ -578,7 +570,6 @@ 12 {{154, 108}, {326, 5}} - {0, 0} 67239424 @@ -601,7 +592,6 @@ 12 {{154, 53}, {326, 5}} - {0, 0} 67239424 @@ -624,7 +614,6 @@ 268 {{38, 23}, {110, 17}} - YES 68288064 @@ -641,7 +630,6 @@ 268 {{153, 20}, {38, 22}} - YES -1804468671 @@ -698,8 +686,8 @@ YES YES - . - , + , + . NO YES NO @@ -720,7 +708,6 @@ 268 {{197, 23}, {162, 17}} - YES 68288064 @@ -734,8 +721,6 @@ {500, 234} - - NSView @@ -748,7 +733,6 @@ 268 {{152, 181}, {123, 18}} - YES 67239424 @@ -771,7 +755,6 @@ 268 {{28, 220}, {120, 17}} - YES 67239488 @@ -788,7 +771,6 @@ 268 {{374, 67}, {38, 17}} - YES 67239488 @@ -805,7 +787,6 @@ 268 {{152, 221}, {106, 18}} - YES -2080244224 @@ -828,7 +809,6 @@ 268 {{152, 66}, {115, 18}} - YES 67239424 @@ -851,7 +831,6 @@ 268 {{152, 201}, {105, 18}} - YES -2080244224 @@ -874,7 +853,6 @@ 268 {{353, 61}, {19, 27}} - YES 917024 @@ -882,7 +860,7 @@ 1.000000e+02 1.000000e+00 - 1.000000e+03 + 5.000000e+04 1.000000e+00 YES YES @@ -893,7 +871,6 @@ 268 {{273, 64}, {75, 22}} - YES -1804468672 @@ -944,8 +921,8 @@ YES YES - . - , + , + . NO YES NO @@ -962,7 +939,6 @@ 268 {{17, 22}, {131, 17}} - YES 68288064 @@ -979,7 +955,6 @@ 268 {{154, 20}, {75, 22}} - YES -1804468671 @@ -998,7 +973,6 @@ 268 {{152, 141}, {297, 18}} - YES 67239424 @@ -1021,7 +995,6 @@ 268 {{152, 121}, {225, 18}} - YES 67239424 @@ -1044,7 +1017,6 @@ 12 {{154, 167}, {326, 5}} - {0, 0} 67239424 @@ -1067,7 +1039,6 @@ 12 {{154, 92}, {326, 5}} - {0, 0} 67239424 @@ -1090,7 +1061,6 @@ 12 {{154, 53}, {326, 5}} - {0, 0} 67239424 @@ -1113,7 +1083,6 @@ 268 {{152, 101}, {206, 18}} - YES -2080244224 @@ -1134,7 +1103,6 @@ {500, 259} - NSView @@ -1320,6 +1288,7 @@ {{1, 1}, {198, 358}} + 4 @@ -1347,6 +1316,7 @@ {{-2, 22}, {200, 360}} + 530 @@ -1810,6 +1780,7 @@ 268 {{152, 173}, {187, 18}} + YES 67239424 @@ -1832,6 +1803,7 @@ 12 {{154, 136}, {334, 5}} + {0, 0} 67239424 @@ -1854,6 +1826,7 @@ 268 {{152, 150}, {261, 18}} + YES 67239424 @@ -1876,6 +1849,7 @@ 268 {{152, 110}, {142, 18}} + YES 67239424 @@ -1898,6 +1872,7 @@ 268 {{180, 87}, {77, 18}} + YES 67239424 @@ -1920,6 +1895,7 @@ 268 {{180, 64}, {123, 18}} + YES 67239424 @@ -1942,6 +1918,7 @@ 268 {{180, 41}, {154, 18}} + YES 67239424 @@ -1964,6 +1941,7 @@ 268 {{180, 18}, {63, 18}} + YES 67239424 @@ -1984,6 +1962,7 @@ {500, 209} + NSView @@ -2225,8 +2204,8 @@ AQAAAAA YES YES - . - , + , + . NO YES YES @@ -2281,7 +2260,7 @@ AQAAAAA NSView - + 268 YES @@ -2297,7 +2276,6 @@ AQAAAAA {{154, 199}, {44, 23}} - YES YES @@ -2317,7 +2295,6 @@ AQAAAAA {{154, 228}, {44, 23}} - YES YES @@ -2337,7 +2314,6 @@ AQAAAAA {{154, 141}, {44, 23}} - YES YES @@ -2357,7 +2333,6 @@ AQAAAAA {{154, 112}, {44, 23}} - YES YES @@ -2377,7 +2352,6 @@ AQAAAAA {{154, 286}, {44, 23}} - YES YES @@ -2397,7 +2371,6 @@ AQAAAAA {{154, 170}, {44, 23}} - YES YES @@ -2417,7 +2390,6 @@ AQAAAAA {{154, 83}, {44, 23}} - YES YES @@ -2437,7 +2409,6 @@ AQAAAAA {{154, 54}, {44, 23}} - YES YES @@ -2457,7 +2428,6 @@ AQAAAAA {{154, 315}, {44, 23}} - YES YES @@ -2477,7 +2447,6 @@ AQAAAAA {{154, 257}, {44, 23}} - YES 1 @@ -2489,7 +2458,6 @@ AQAAAAA 268 {{86, 202}, {63, 17}} - YES 68288064 @@ -2506,7 +2474,6 @@ AQAAAAA 268 {{88, 173}, {61, 17}} - YES 68288064 @@ -2523,7 +2490,6 @@ AQAAAAA 268 {{79, 231}, {70, 17}} - YES 68288064 @@ -2540,7 +2506,6 @@ AQAAAAA 268 {{89, 86}, {60, 17}} - YES 68288064 @@ -2557,7 +2522,6 @@ AQAAAAA 268 {{23, 58}, {125, 17}} - YES 68288064 @@ -2574,7 +2538,6 @@ AQAAAAA 268 {{102, 144}, {47, 17}} - YES 68288064 @@ -2591,7 +2554,6 @@ AQAAAAA 268 {{112, 318}, {37, 17}} - YES 68288064 @@ -2608,7 +2570,6 @@ AQAAAAA 268 {{46, 115}, {103, 17}} - YES 68288064 @@ -2625,7 +2586,6 @@ AQAAAAA 268 {{66, 289}, {83, 17}} - YES 68288064 @@ -2642,7 +2602,6 @@ AQAAAAA 268 {{113, 357}, {36, 17}} - YES 68288064 @@ -2659,7 +2618,6 @@ AQAAAAA 268 {{73, 12}, {131, 32}} - YES -2080244224 @@ -2680,7 +2638,6 @@ AQAAAAA 268 {{396, 347}, {90, 32}} - YES 67239424 @@ -2701,7 +2658,6 @@ AQAAAAA 268 {{154, 355}, {240, 19}} - YES -2076049856 @@ -2719,7 +2675,6 @@ AQAAAAA 268 {{107, 260}, {42, 17}} - YES 605158976 @@ -2736,7 +2691,6 @@ AQAAAAA 268 {{257, 317}, {126, 18}} - YES -2080244224 @@ -2759,7 +2713,6 @@ AQAAAAA 268 {{257, 288}, {150, 18}} - YES -2080244224 @@ -2782,7 +2735,6 @@ AQAAAAA 268 {{257, 230}, {179, 18}} - YES 67239424 @@ -2805,7 +2757,6 @@ AQAAAAA 268 {{257, 259}, {185, 18}} - YES -2080244224 @@ -2828,7 +2779,6 @@ AQAAAAA 268 {{257, 173}, {185, 18}} - YES -2080244224 @@ -2851,7 +2801,6 @@ AQAAAAA -2147483380 {{257, 144}, {197, 18}} - YES -1543373312 @@ -2874,7 +2823,6 @@ AQAAAAA 268 {{357, 205}, {29, 19}} - YES -1538130368 @@ -2950,7 +2898,6 @@ AQAAAAA 268 {{298, 207}, {54, 14}} - YES 605158976 @@ -2967,7 +2914,6 @@ AQAAAAA 268 {{392, 203}, {15, 22}} - YES 604896800 @@ -2986,7 +2932,6 @@ AQAAAAA 268 {{410, 207}, {27, 14}} - YES 605158976 @@ -3003,7 +2948,6 @@ AQAAAAA 12 {{154, 344}, {326, 5}} - {0, 0} 67239424 @@ -3023,20 +2967,9 @@ AQAAAAA {500, 395} - - NSView - - YES - ConsoleEnableLogging - LogInterfaceQueries - EnableInterfaceLogging - EnableImportExportLogging - EnableCustomQueryLogging - EnableErrorLogging - YES @@ -7283,7 +7216,7 @@ AQAAAAA com.apple.InterfaceBuilder.CocoaPlugin - {{513, 312}, {500, 259}} + {{406, 312}, {500, 259}} com.apple.InterfaceBuilder.CocoaPlugin YES diff --git a/Source/CMCopyTable.m b/Source/CMCopyTable.m index 2f7bb929..85f8a20e 100644 --- a/Source/CMCopyTable.m +++ b/Source/CMCopyTable.m @@ -101,7 +101,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002; if(withHeaders) { int i; for( i = 0; i < numColumns; i++ ){ - [result appendString:[NSString stringWithFormat:@"%@\t", [[[columns objectAtIndex:i] headerCell] stringValue]]]; + [result appendString:[NSString stringWithFormat:@"%@\t", [[NSArrayObjectAtIndex(columns, i) headerCell] stringValue]]]; } [result appendString:[NSString stringWithFormat:@"\n"]]; } @@ -119,7 +119,7 @@ int MENU_EDIT_COPY_AS_SQL = 2002; rowData = nil; for ( c = 0; c < numColumns; c++) { - col = [columns objectAtIndex:c]; + col = NSArrayObjectAtIndex(columns, c); rowData = [dataSource tableView:self objectValueForTableColumn:col row:[row intValue] ]; diff --git a/Source/CMMCPConnection.h b/Source/CMMCPConnection.h index 4005c19b..81b25535 100644 --- a/Source/CMMCPConnection.h +++ b/Source/CMMCPConnection.h @@ -78,7 +78,13 @@ IMP cStringPtr; IMP willQueryStringPtr; + IMP stopKeepAliveTimerPtr; + IMP startKeepAliveTimerResettingStatePtr; + SEL cStringSEL; + SEL willQueryStringSEL; + SEL stopKeepAliveTimerSEL; + SEL startKeepAliveTimerResettingStateSEL; } - (id) init; diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m index 4cc2fccf..3101beb9 100644 --- a/Source/CMMCPConnection.m +++ b/Source/CMMCPConnection.m @@ -140,7 +140,14 @@ static void forcePingTimeout(int signalNumber); NSLog(@"Connection error dialog could not be loaded; connection failure handling will not function correctly."); } - cStringPtr = [self methodForSelector:@selector(cStringFromString:usingEncoding:)]; + willQueryStringSEL = @selector(willQueryString:); + stopKeepAliveTimerSEL = @selector(stopKeepAliveTimer); + startKeepAliveTimerResettingStateSEL = @selector(startKeepAliveTimerResettingState:); + cStringSEL = @selector(cStringFromString:); + + cStringPtr = [self methodForSelector:cStringSEL]; + stopKeepAliveTimerPtr = [self methodForSelector:stopKeepAliveTimerSEL]; + startKeepAliveTimerResettingStatePtr = [self methodForSelector:startKeepAliveTimerResettingStateSEL]; } @@ -740,14 +747,14 @@ static void forcePingTimeout(int signalNumber); return nil; } - [self stopKeepAliveTimer]; + (void)(*stopKeepAliveTimerPtr)(self, stopKeepAliveTimerSEL); // queryStartTime = clock(); // Inform the delegate about the query if logging is enabled and // delegate responds to willQueryString: if (consoleLoggingEnabled && delegateResponseToWillQueryString) - (void)(NSString*)(*willQueryStringPtr)(delegate, @selector(willQueryString:), query); + (void)(NSString*)(*willQueryStringPtr)(delegate, willQueryStringSEL, query); // Derive the query string in the correct encoding switch(encoding) { @@ -755,7 +762,7 @@ static void forcePingTimeout(int signalNumber); theCQuery = NSStringUTF8String(query); break; default: - theCQuery = (const char*)(NSString*)(int)(*cStringPtr)(self, @selector(cStringFromString:), query, encoding); + theCQuery = (const char*)(NSString*)(int)(*cStringPtr)(self, cStringSEL, query, encoding); //[self cStringFromString:query usingEncoding:encoding]; } @@ -864,7 +871,7 @@ static void forcePingTimeout(int signalNumber); if (queryResultCode & delegateResponseToWillQueryString) [delegate queryGaveError:lastQueryErrorMessage]; - [self startKeepAliveTimerResettingState:YES]; + (void)(int)(*startKeepAliveTimerResettingStatePtr)(self, startKeepAliveTimerResettingStateSEL, YES); if (!theResult) return nil; return [theResult autorelease]; @@ -950,7 +957,7 @@ static void forcePingTimeout(int signalNumber); if (delegate && [delegate valueForKey:@"_encoding"]) { [self queryString:[NSString stringWithFormat:@"/*!40101 SET NAMES '%@' */", [NSString stringWithString:[delegate valueForKey:@"_encoding"]]]]; if (delegate && [delegate respondsToSelector:@selector(connectionEncodingViaLatin1)]) { - if ([delegate connectionEncodingViaLatin1]) [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"]; + if ([delegate connectionEncodingViaLatin1]) [self queryString:@"/*!40101 SET CHARACTER_SET_RESULTS=latin1 */"]; } } } @@ -958,8 +965,11 @@ static void forcePingTimeout(int signalNumber); - (void)setDelegate:(id)object { delegate = object; - delegateResponseToWillQueryString = (delegate && [delegate respondsToSelector:@selector(willQueryString:)]); - willQueryStringPtr = [delegate methodForSelector:@selector(willQueryString:)]; + + delegateResponseToWillQueryString = (delegate && [delegate respondsToSelector:willQueryStringSEL]); + + willQueryStringPtr = [delegate methodForSelector:willQueryStringSEL]; + } /* Getting the currently used time zone (in communication with the DB server). */ diff --git a/Source/CMMCPResult.m b/Source/CMMCPResult.m index 701e614c..ebc5c6ab 100644 --- a/Source/CMMCPResult.m +++ b/Source/CMMCPResult.m @@ -24,6 +24,7 @@ // More info at #import "CMMCPResult.h" +#import "SPArrayAdditions.h" @implementation CMMCPResult @@ -295,7 +296,7 @@ modified version for use with sequel-pro switch (aType) { case MCPTypeDictionary : - [theReturn setObject:theCurrentObj forKey:[mNames objectAtIndex:i]]; + [theReturn setObject:theCurrentObj forKey:NSArrayObjectAtIndex(mNames, i)]; break; case MCPTypeArray : diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 8e891b20..313a88bc 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -26,6 +26,7 @@ #import "CustomQuery.h" #import "TableDocument.h" #import "SPStringAdditions.h" +#import "SPArrayAdditions.h" #import "SPTextViewAdditions.h" #import "SPNarrowDownCompletion.h" @@ -138,7 +139,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) [queryResult dataSeek:0]; for (i = 0 ; i < [queryResult numOfRows] ; i++) { - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:0], @"display", @"table-small-square", @"image", nil]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0), @"display", @"table-small-square", @"image", nil]]; //[possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; } @@ -158,7 +159,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) for (i = 0 ; i < [queryResult numOfRows] ; i++) { // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:0], @"display", @"database-small", @"image", nil]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0), @"display", @"database-small", @"image", nil]]; } // Add proc/func only for MySQL version 5 or higher @@ -170,7 +171,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) for (i = 0 ; i < [queryResult numOfRows] ; i++) { // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:1], @"display", @"proc-small", @"image", nil]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 1), @"display", @"proc-small", @"image", nil]]; } // Add all function to completions list for currently selected table @@ -180,7 +181,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) for (i = 0 ; i < [queryResult numOfRows] ; i++) { // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:[[queryResult fetchRowAsArray] objectAtIndex:1], @"display", @"func-small", @"image", nil]]; + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 1), @"display", @"func-small", @"image", nil]]; } } @@ -988,7 +989,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) for (i = 0; i < [matchingCompletions count]; i++) { - NSString* obj = [matchingCompletions objectAtIndex:i]; + NSString* obj = NSArrayObjectAtIndex(matchingCompletions, i); if(![compl containsObject:obj]) if ([partialString isEqualToString:[obj substringToIndex:partialLength]]) // Matches case --> Insert at beginning of completion list diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index b59fe084..eab76897 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -28,6 +28,7 @@ #import "SPGrowlController.h" #import "SPStringAdditions.h" #import "SPTextViewAdditions.h" +#import "SPArrayAdditions.h" #import "TableDocument.h" #import "TablesList.h" #import "RegexKitLite.h" @@ -410,14 +411,16 @@ // Remove all the columns theColumns = [customQueryView tableColumns]; while ([theColumns count]) { - [customQueryView removeTableColumn:[theColumns objectAtIndex:0]]; + [customQueryView removeTableColumn:NSArrayObjectAtIndex(theColumns, 0)]; } + long queryCount = [queries count]; + // Perform the supplied queries in series - for ( i = 0 ; i < [queries count] ; i++ ) { + for ( i = 0 ; i < queryCount ; i++ ) { // Don't run blank queries, or queries which only contain whitespace. - if ([[[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewlineSet] length] == 0) + if ([[NSArrayObjectAtIndex(queries, i) stringByTrimmingCharactersInSet:whitespaceAndNewlineSet] length] == 0) continue; // Run the query, timing execution (note this also includes network and overhead) @@ -433,7 +436,7 @@ if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { // If the query errored, append error to the error log for display at the end - if ( [queries count] > 1 ) { + if ( queryCount > 1 ) { if(firstErrorOccuredInQuery == -1) firstErrorOccuredInQuery = i+1; @@ -705,7 +708,7 @@ // the extra semicolon at the end of each query for (i = 0; i < queryCount; i++ ) { - queryRange = [[queries objectAtIndex:i] rangeValue]; + queryRange = [NSArrayObjectAtIndex(queries, i) rangeValue]; queryPosition = NSMaxRange(queryRange); queryStartPosition = queryRange.location; @@ -722,7 +725,7 @@ if (position == queryStartPosition) positionAssociatedWithPreviousQuery = YES; // If the caret is in between a user-defined delimiter whose length is >1, always associate - if (!positionAssociatedWithPreviousQuery && i && NSMaxRange([[queries objectAtIndex:i-1] rangeValue]) < position && position < queryStartPosition) positionAssociatedWithPreviousQuery = YES; + if (!positionAssociatedWithPreviousQuery && i && NSMaxRange([NSArrayObjectAtIndex(queries, i-1) rangeValue]) < position && position < queryStartPosition) positionAssociatedWithPreviousQuery = YES; // Otherwise associate if only whitespace since previous, and a newline before next. if (!positionAssociatedWithPreviousQuery) { @@ -742,7 +745,7 @@ } // If there is a previous query and the position should be associated with it, do so. - if (i && positionAssociatedWithPreviousQuery && [[[[textView string] substringWithRange:[[queries objectAtIndex:i-1] rangeValue]] stringByTrimmingCharactersInSet:whitespaceAndNewlineSet] length]) { + if (i && positionAssociatedWithPreviousQuery && [[[[textView string] substringWithRange:[NSArrayObjectAtIndex(queries, i-1) rangeValue]] stringByTrimmingCharactersInSet:whitespaceAndNewlineSet] length]) { queryRange = [[queries objectAtIndex:i-1] rangeValue]; break; } @@ -1053,8 +1056,8 @@ NSRunAlertPanel(@"Query already exists", @"The query you are adding to your favorites already exists.", @"OK", nil, nil); //remove row if it was a (blank) new row or a copied row - if ( [[queryFavorites objectAtIndex:rowIndex] isEqualToString:@""] || - [[queryFavorites objectAtIndex:rowIndex] isEqualToString:anObject] ) { + if ( [NSArrayObjectAtIndex(queryFavorites, rowIndex) isEqualToString:@""] || + [NSArrayObjectAtIndex(queryFavorites, rowIndex) isEqualToString:anObject] ) { [queryFavoritesView deselectAll:self]; [queryFavorites removeObjectAtIndex:rowIndex]; [queryFavoritesView reloadData]; diff --git a/Source/NoodleLineNumberView.m b/Source/NoodleLineNumberView.m index 2cd2508a..1743782b 100644 --- a/Source/NoodleLineNumberView.m +++ b/Source/NoodleLineNumberView.m @@ -31,6 +31,7 @@ // functionality and adds selection by clicking on the ruler. #import "NoodleLineNumberView.h" +#import "SPArrayAdditions.h" #define DEFAULT_THICKNESS 22.0 #define RULER_MARGIN 5.0 @@ -207,7 +208,7 @@ for (line = 0; line < count; line++) { - index = [[lines objectAtIndex:line] unsignedIntValue]; + index = [NSArrayObjectAtIndex(lines, line) unsignedIntValue]; rects = [layoutManager rectArrayForCharacterRange:NSMakeRange(index, 0) withinSelectedCharacterRange:nullRange @@ -299,7 +300,7 @@ while ((right - left) > 1) { mid = (right + left) / 2; - lineStart = [[lines objectAtIndex:mid] unsignedIntValue]; + lineStart = [NSArrayObjectAtIndex(lines, mid) unsignedIntValue]; if (index < lineStart) { @@ -405,7 +406,7 @@ for (line = [self lineNumberForCharacterIndex:range.location inText:text]; line < count; line++) { - index = [[lines objectAtIndex:line] unsignedIntValue]; + index = [NSArrayObjectAtIndex(lines, line) unsignedIntValue]; if (NSLocationInRange(index, range)) { diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h index 7a672dc0..044699db 100644 --- a/Source/SPArrayAdditions.h +++ b/Source/SPArrayAdditions.h @@ -24,6 +24,15 @@ #import +static inline id NSArrayObjectAtIndex(NSArray* self, NSUInteger i) { + typedef id (*SPArrayObjectAtIndexMethodPtr)(NSArray*, SEL, NSUInteger); + static SPArrayObjectAtIndexMethodPtr SPNSArrayObjectAtIndex; + if (!SPNSArrayObjectAtIndex) SPNSArrayObjectAtIndex = (SPArrayObjectAtIndexMethodPtr)[self methodForSelector:@selector(objectAtIndex:)]; + id to_return = SPNSArrayObjectAtIndex(self, @selector(objectAtIndex:), i); + return to_return; +} + + @interface NSArray (SPArrayAdditions) - (NSString *)componentsJoinedAndBacktickQuoted; diff --git a/Source/SPExportController.m b/Source/SPExportController.m index bd72c9d2..b76ea41f 100644 --- a/Source/SPExportController.m +++ b/Source/SPExportController.m @@ -24,6 +24,7 @@ #import "SPExportController.h" #import "TablesList.h" +#import "SPArrayAdditions.h" @implementation SPExportController @@ -78,7 +79,7 @@ for ( i = 0 ; i < [queryResult numOfRows] ; i++ ) { [tables addObject:[NSMutableArray arrayWithObjects: [NSNumber numberWithBool:YES], - [[queryResult fetchRowAsArray] objectAtIndex:0], + NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0), nil ]]; } @@ -118,9 +119,9 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn id returnObject = nil; if ( [[aTableColumn identifier] isEqualToString:@"switch"] ) { - returnObject = [[tables objectAtIndex:rowIndex] objectAtIndex:0]; + returnObject = NSArrayObjectAtIndex([tables objectAtIndex:rowIndex], 0); } else { - returnObject = [[tables objectAtIndex:rowIndex] objectAtIndex:1]; + returnObject = NSArrayObjectAtIndex([tables objectAtIndex:rowIndex], 1); } return returnObject; diff --git a/Source/SPNarrowDownCompletion.m b/Source/SPNarrowDownCompletion.m index e5dc43ea..591b40d0 100644 --- a/Source/SPNarrowDownCompletion.m +++ b/Source/SPNarrowDownCompletion.m @@ -27,6 +27,7 @@ // More info at #import "SPNarrowDownCompletion.h" +#import "SPArrayAdditions.h" #import "ImageAndTextCell.h" #import @@ -268,9 +269,9 @@ for(i=0; i<[newFiltered count]; i++) { if(dictMode) - item = [newFiltered objectAtIndex:i]; + item = NSArrayObjectAtIndex([newFiltered objectAtIndex:i], 0); else - item = [[newFiltered objectAtIndex:i] objectForKey:@"display"]; + item = [NSArrayObjectAtIndex([newFiltered objectAtIndex:i], 0) objectForKey:@"display"]; // If space in suggestion add space to allowed input chars if(!spaceInSuggestion && [item rangeOfString:@" "].length) { [textualInputCharacters addCharactersInString:@" "]; diff --git a/Source/SPQueryConsole.m b/Source/SPQueryConsole.m index dab9a9a0..d7f29811 100644 --- a/Source/SPQueryConsole.m +++ b/Source/SPQueryConsole.m @@ -25,6 +25,7 @@ #import "SPQueryConsole.h" #import "SPConsoleMessage.h" +#import "SPArrayAdditions.h" #define MESSAGE_TRUNCATE_CHARACTER_LENGTH 256 #define MESSAGE_TIME_STAMP_FORMAT @"%H:%M:%S" @@ -147,7 +148,7 @@ static SPQueryConsole *sharedQueryConsole = nil; while (i != NSNotFound) { if (i < [messagesVisibleSet count]) { - SPConsoleMessage *message = [messagesVisibleSet objectAtIndex:i]; + SPConsoleMessage *message = NSArrayObjectAtIndex(messagesVisibleSet, i); NSString *consoleMessage = [message message]; diff --git a/Source/SPTableData.m b/Source/SPTableData.m index f2e0c77e..8fd2f26c 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -31,6 +31,7 @@ #import "TableDocument.h" #import "TablesList.h" #import "SPStringAdditions.h" +#import "SPArrayAdditions.h" @implementation SPTableData @@ -339,10 +340,13 @@ tableColumn = [[NSMutableDictionary alloc] init]; definitionParts = [[NSMutableArray alloc] init]; fieldParser = [[SPSQLParser alloc] init]; + + NSCharacterSet *whitespaceAndNewlineSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; + for (i = 0; i < [fieldStrings count]; i++) { // Take this field/key string, trim whitespace from both ends and remove comments - [fieldsParser setString:[[fieldStrings objectAtIndex:i] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]; + [fieldsParser setString:[NSArrayObjectAtIndex(fieldStrings, i) stringByTrimmingCharactersInSet:whitespaceAndNewlineSet]]; [fieldsParser deleteComments]; if (![fieldsParser length]) { continue; @@ -411,60 +415,60 @@ // NOTE: this won't get SET NULL | NO ACTION if( [[parts objectAtIndex:9] hasPrefix:@"UPDATE"] ) { //NSLog( @"update: %@", [parts objectAtIndex:10] ); - if( [[parts objectAtIndex:10] hasPrefix:@"SET"] ) { + if( [NSArrayObjectAtIndex(parts, 10) hasPrefix:@"SET"] ) { [constraintDetails setObject:@"SET NULL" forKey:@"update"]; nextOffs = 13; - } else if( [[parts objectAtIndex:10] hasPrefix:@"NO"] ) { + } else if( [NSArrayObjectAtIndex(parts, 10) hasPrefix:@"NO"] ) { [constraintDetails setObject:@"NO ACTION" forKey:@"update"]; nextOffs = 13; } else { - [constraintDetails setObject:[parts objectAtIndex:10] - forKey:@"update"]; + [constraintDetails setObject:NSArrayObjectAtIndex(parts, 10) + forKey:@"update"]; } } - else if( [[parts objectAtIndex:9] hasPrefix:@"DELETE"] ) { - //NSLog( @"delete: %@", [parts objectAtIndex:10] ); - if( [[parts objectAtIndex:10] hasPrefix:@"SET"] ) { + else if( [NSArrayObjectAtIndex(parts, 9) hasPrefix:@"DELETE"] ) { + //NSLog( @"delete: %@", [parts objectAtIndex:10] ); + if( [NSArrayObjectAtIndex(parts, 10) hasPrefix:@"SET"] ) { [constraintDetails setObject:@"SET NULL" forKey:@"delete"]; nextOffs = 13; - } else if( [[parts objectAtIndex:10] hasPrefix:@"NO"] ) { + } else if( [NSArrayObjectAtIndex(parts, 10) hasPrefix:@"NO"] ) { [constraintDetails setObject:@"NO ACTION" forKey:@"delete"]; nextOffs = 13; } else { - [constraintDetails setObject:[parts objectAtIndex:10] - forKey:@"delete"]; + [constraintDetails setObject:NSArrayObjectAtIndex(parts, 10) + forKey:@"delete"]; } } } if( [parts count] > nextOffs - 1 ) { - if( [[parts objectAtIndex:nextOffs] hasPrefix:@"UPDATE"] ) { + if( [NSArrayObjectAtIndex(parts, nextOffs) hasPrefix:@"UPDATE"] ) { //NSLog( @"update: %@", [parts objectAtIndex:13] ); - if( [[parts objectAtIndex:nextOffs+1] hasPrefix:@"SET"] ) { + if( [NSArrayObjectAtIndex(parts, nextOffs+1) hasPrefix:@"SET"] ) { [constraintDetails setObject:@"SET NULL" forKey:@"update"]; - } else if( [[parts objectAtIndex:nextOffs+1] hasPrefix:@"NO"] ) { + } else if( [NSArrayObjectAtIndex(parts, nextOffs+1) hasPrefix:@"NO"] ) { [constraintDetails setObject:@"NO ACTION" forKey:@"update"]; } else { - [constraintDetails setObject:[parts objectAtIndex:nextOffs+1] - forKey:@"update"]; + [constraintDetails setObject:NSArrayObjectAtIndex(parts, nextOffs+1) + forKey:@"update"]; } } - else if( [[parts objectAtIndex:nextOffs] hasPrefix:@"DELETE"] ) { - //NSLog( @"delete: %@", [parts objectAtIndex:13] ); - if( [[parts objectAtIndex:nextOffs+1] hasPrefix:@"SET"] ) { + else if( [NSArrayObjectAtIndex(parts, nextOffs) hasPrefix:@"DELETE"] ) { + //NSLog( @"delete: %@", [parts objectAtIndex:13] ); + if( [NSArrayObjectAtIndex(parts, nextOffs+1) hasPrefix:@"SET"] ) { [constraintDetails setObject:@"SET NULL" forKey:@"delete"]; - } else if( [[parts objectAtIndex:nextOffs+1] hasPrefix:@"NO"] ) { + } else if( [NSArrayObjectAtIndex(parts, nextOffs+1) hasPrefix:@"NO"] ) { [constraintDetails setObject:@"NO ACTION" forKey:@"delete"]; } else { - [constraintDetails setObject:[parts objectAtIndex:nextOffs+1] - forKey:@"delete"]; + [constraintDetails setObject:NSArrayObjectAtIndex(parts, nextOffs+1) + forKey:@"delete"]; } } } @@ -472,11 +476,11 @@ [constraintDetails release]; } // primary key - else if( [[parts objectAtIndex:0] hasPrefix:@"PRIMARY"] ) { - //NSLog( @"pkey is %@", [[parts objectAtIndex:2] stringByTrimmingCharactersInSet:junk] ); + else if( [NSArrayObjectAtIndex(parts, 0) hasPrefix:@"PRIMARY"] ) { + //NSLog( @"pkey is %@", [[parts objectAtIndex:2] stringByTrimmingCharactersInSet:junk] ); } // key - else if( [[parts objectAtIndex:0] hasPrefix:@"KEY"] ) { + else if( [NSArrayObjectAtIndex(parts, 0) hasPrefix:@"KEY"] ) { /* NSLog( @"key %@.%@", [[parts objectAtIndex:1] stringByTrimmingCharactersInSet:junk], diff --git a/Source/TableContent.m b/Source/TableContent.m index bbda4d44..4d68ce1f 100644 --- a/Source/TableContent.m +++ b/Source/TableContent.m @@ -109,7 +109,7 @@ theColumns = [tableContentView tableColumns]; while ([theColumns count]) { - [tableContentView removeTableColumn:[theColumns objectAtIndex:0]]; + [tableContentView removeTableColumn:NSArrayObjectAtIndex(theColumns, 0)]; } // If no table has been supplied, reset the view to a blank table and disabled elements. @@ -167,7 +167,7 @@ // Add the new columns to the table for ( i = 0 ; i < [theColumns count] ; i++ ) { - columnDefinition = [theColumns objectAtIndex:i]; + columnDefinition = NSArrayObjectAtIndex(theColumns, i); // Set up the column theCol = [[NSTableColumn alloc] initWithIdentifier:[columnDefinition objectForKey:@"name"]]; @@ -718,7 +718,7 @@ columns = [[NSArray alloc] initWithArray:[tableDataInstance columns]]; for ( i = 0 ; i < [columns count] ; i++ ) { - column = [columns objectAtIndex:i]; + column = NSArrayObjectAtIndex(columns, i); if ([column objectForKey:@"default"] == nil || [[column objectForKey:@"default"] isEqualToString:@"NULL"]) { [newRow setObject:[prefs stringForKey:@"NullValue"] forKey:[column objectForKey:@"name"]]; } else { @@ -1438,8 +1438,8 @@ // Add values for hidden blob and text fields if appropriate if ( [prefs boolForKey:@"LoadBlobsAsNeeded"] ) { for ( j = 0 ; j < [columns count] ; j++ ) { - if ( [tableDataInstance columnIsBlobOrText:[[columns objectAtIndex:j] objectForKey:@"name"] ] ) { - [modifiedRow setObject:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields") forKey:[[columns objectAtIndex:j] objectForKey:@"name"]]; + if ( [tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(columns, j) objectForKey:@"name"] ] ) { + [modifiedRow setObject:NSLocalizedString(@"(not loaded)", @"value shown for hidden blob and text fields") forKey:[NSArrayObjectAtIndex(columns, j) objectForKey:@"name"]]; } } } @@ -1489,7 +1489,7 @@ NSMutableArray *fieldValues = [[NSMutableArray alloc] init]; // Get the field values for ( i = 0 ; i < [columnNames count] ; i++ ) { - rowObject = [[filteredResult objectAtIndex:currentlyEditingRow] objectForKey:[columnNames objectAtIndex:i]]; + rowObject = [NSArrayObjectAtIndex(filteredResult, currentlyEditingRow) objectForKey:NSArrayObjectAtIndex(columnNames, i)]; // Convert the object to a string (here we can add special treatment for date-, number- and data-fields) if ( [[rowObject description] isEqualToString:[prefs stringForKey:@"NullValue"]] || ([rowObject isMemberOfClass:[NSString class]] && [[rowObject description] isEqualToString:@""]) ) { @@ -1510,7 +1510,7 @@ } else { if ( [[rowObject description] isEqualToString:@"CURRENT_TIMESTAMP"] ) { [rowValue setString:@"CURRENT_TIMESTAMP"]; - } else if ([[[theColumns objectAtIndex:i] objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { + } else if ([[NSArrayObjectAtIndex(theColumns, i) objectForKey:@"typegrouping"] isEqualToString:@"bit"]) { [rowValue setString:((![[rowObject description] length] || [[rowObject description] isEqualToString:@"0"])?@"0":@"1")]; } else { [rowValue setString:[NSString stringWithFormat:@"'%@'", [mySQLConnection prepareString:[rowObject description]]]]; @@ -1533,7 +1533,7 @@ [queryString appendString:@", "]; } [queryString appendString:[NSString stringWithFormat:@"%@=%@", - [[columnNames objectAtIndex:i] backtickQuotedString], [fieldValues objectAtIndex:i]]]; + [NSArrayObjectAtIndex(columnNames, i) backtickQuotedString], [fieldValues objectAtIndex:i]]]; } [queryString appendString:[NSString stringWithFormat:@" WHERE %@", [self argumentForRow:-2]]]; } @@ -1570,9 +1570,9 @@ // Set the insertId for fields with auto_increment for ( i = 0; i < [theColumns count] ; i++ ) { - if ([[[theColumns objectAtIndex:i] objectForKey:@"autoincrement"] intValue]) { + if ([[NSArrayObjectAtIndex(theColumns, i) objectForKey:@"autoincrement"] intValue]) { [[filteredResult objectAtIndex:currentlyEditingRow] setObject:[[NSNumber numberWithLong:[mySQLConnection insertId]] description] - forKey:[columnNames objectAtIndex:i]]; + forKey:NSArrayObjectAtIndex(columnNames, i)]; } } [fullResult addObject:[filteredResult objectAtIndex:currentlyEditingRow]]; @@ -1710,11 +1710,11 @@ // Use the selected row if appropriate if ( row >= 0 ) { - tempValue = [[filteredResult objectAtIndex:row] objectForKey:[keys objectAtIndex:i]]; + tempValue = [NSArrayObjectAtIndex(filteredResult, row) objectForKey:NSArrayObjectAtIndex(keys, i)]; // Otherwise use the oldRow } else { - tempValue = [oldRow objectForKey:[keys objectAtIndex:i]]; + tempValue = [oldRow objectForKey:NSArrayObjectAtIndex(keys, i)]; } if ( [tempValue isKindOfClass:[NSData class]] ) { @@ -1728,7 +1728,7 @@ } if ( [value isEqualToString:[prefs stringForKey:@"NullValue"]] ) { - [argument appendString:[NSString stringWithFormat:@"%@ IS NULL", [[keys objectAtIndex:i] backtickQuotedString]]]; + [argument appendString:[NSString stringWithFormat:@"%@ IS NULL", [NSArrayObjectAtIndex(keys, i) backtickQuotedString]]]; } else { // Escape special characters (in WHERE statement!) @@ -1750,9 +1750,9 @@ columnType = [[tableDataInstance columnWithName:[keys objectAtIndex:i]] objectForKey:@"typegrouping"]; if ( [columnType isEqualToString:@"integer"] || [columnType isEqualToString:@"float"] || [columnType isEqualToString:@"bit"] ) { - [argument appendString:[NSString stringWithFormat:@"%@ = %@", [[keys objectAtIndex:i] backtickQuotedString], value]]; + [argument appendString:[NSString stringWithFormat:@"%@ = %@", [NSArrayObjectAtIndex(keys, i) backtickQuotedString], value]]; } else { - [argument appendString:[NSString stringWithFormat:@"%@ LIKE %@", [[keys objectAtIndex:i] backtickQuotedString], value]]; + [argument appendString:[NSString stringWithFormat:@"%@ LIKE %@", [NSArrayObjectAtIndex(keys, i) backtickQuotedString], value]]; } } } @@ -1772,7 +1772,7 @@ NSArray *tableColumns = [tableDataInstance columns]; for ( i = 0 ; i < [tableColumns count]; i++ ) { - if ( [tableDataInstance columnIsBlobOrText:[[tableColumns objectAtIndex:i] objectForKey:@"name"]] ) { + if ( [tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(tableColumns, i) objectForKey:@"name"]] ) { return YES; } } @@ -1793,14 +1793,14 @@ if ( [prefs boolForKey:@"LoadBlobsAsNeeded"] ) { for ( i = 0 ; i < [columnNames count] ; i++ ) { - if (![tableDataInstance columnIsBlobOrText:[[columns objectAtIndex:i] objectForKey:@"name"]] ) { - [fields addObject:[columnNames objectAtIndex:i]]; + if (![tableDataInstance columnIsBlobOrText:[NSArrayObjectAtIndex(columns, i) objectForKey:@"name"]] ) { + [fields addObject:NSArrayObjectAtIndex(columnNames, i)]; } } // Always select at least one field - the first if there are no non-blob fields. if ( [fields count] == 0 ) { - return [[columnNames objectAtIndex:0] backtickQuotedString]; + return [NSArrayObjectAtIndex(columnNames, 0) backtickQuotedString]; } else { return [fields componentsJoinedAndBacktickQuoted]; } @@ -1893,7 +1893,7 @@ } else { for ( i = 0 ; i < [filteredResult count] ; i++ ) { if ( ![tempArray containsObject:[NSNumber numberWithInt:i]] ) - [tempResult addObject:[filteredResult objectAtIndex:i]]; + [tempResult addObject:NSArrayObjectAtIndex(filteredResult, i)]; } [filteredResult setArray:tempResult]; numRows = [self getNumberOfRows]; @@ -2431,7 +2431,7 @@ objectValueForTableColumn:(NSTableColumn *)aTableColumn // Check if next column is a blob column, and skip to the next non-blob column i = 1; while ( - (fieldType = [[tableDataInstance columnWithName:[[[tableContentView tableColumns] objectAtIndex:column+i] identifier]] objectForKey:@"typegrouping"]) + (fieldType = [[tableDataInstance columnWithName:[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) identifier]] objectForKey:@"typegrouping"]) && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]) ) { i++; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 270ebe5b..f98a2c1c 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -40,6 +40,7 @@ #import "SPTableData.h" #import "SPDatabaseData.h" #import "SPStringAdditions.h" +#import "SPArrayAdditions.h" #import "SPQueryConsole.h" #import "CMMCPConnection.h" #import "CMMCPResult.h" @@ -794,7 +795,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum for (i = 0 ; i < [queryResult numOfRows] ; i++) { - [chooseDatabaseButton addItemWithTitle:[[queryResult fetchRowAsArray] objectAtIndex:0]]; + [chooseDatabaseButton addItemWithTitle:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0)]; } (![self database]) ? [chooseDatabaseButton selectItemAtIndex:0] : [chooseDatabaseButton selectItemWithTitle:[self database]]; @@ -951,7 +952,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum int r = [theResult numOfRows]; if (r) [theResult dataSeek:0]; for ( i = 0 ; i < r ; i++ ) { - dbName = [[theResult fetchRowAsArray] objectAtIndex:0]; + dbName = NSArrayObjectAtIndex([theResult fetchRowAsArray], 0); } if(![dbName isKindOfClass:[NSNull class]]) { if(![dbName isEqualToString:selectedDatabase]) { diff --git a/Source/TableDump.m b/Source/TableDump.m index a309c22a..1490299a 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -53,7 +53,7 @@ if ([queryResult numOfRows]) [queryResult dataSeek:0]; for ( i = 0 ; i < [queryResult numOfRows] ; i++ ) { [tables addObject:[NSMutableArray arrayWithObjects: - [NSNumber numberWithBool:YES], [[queryResult fetchRowAsArray] objectAtIndex:0], nil]]; + [NSNumber numberWithBool:YES], NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0), nil]]; } [exportDumpTableView reloadData]; @@ -481,10 +481,9 @@ if (importSQLAsUTF8) for ( i = 0 ; i < queryCount ; i++ ) { [singleProgressBar setDoubleValue:(i*100/queryCount)]; - // [singleProgressBar displayIfNeeded]; // Skip blank or whitespace-only queries to avoid errors - NSString *q = [[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewline]; + NSString *q = [NSArrayObjectAtIndex(queries, i) stringByTrimmingCharactersInSet:whitespaceAndNewline]; if (![q length]) continue; [mySQLConnection queryString:q usingEncoding:NSUTF8StringEncoding]; @@ -496,10 +495,9 @@ else for ( i = 0 ; i < queryCount ; i++ ) { [singleProgressBar setDoubleValue:(i*100/queryCount)]; - // [singleProgressBar displayIfNeeded]; // Skip blank or whitespace-only queries to avoid errors - NSString *q = [[queries objectAtIndex:i] stringByTrimmingCharactersInSet:whitespaceAndNewline]; + NSString *q = [NSArrayObjectAtIndex(queries, i) stringByTrimmingCharactersInSet:whitespaceAndNewline]; if (![q length]) continue; [mySQLConnection queryString:q]; @@ -591,7 +589,7 @@ theResult = (CMMCPResult *) [mySQLConnection listTables]; if ([theResult numOfRows]) [theResult dataSeek:0]; for ( i = 0 ; i < [theResult numOfRows] ; i++ ) { - [fieldMappingPopup addItemWithTitle:[[theResult fetchRowAsArray] objectAtIndex:0]]; + [fieldMappingPopup addItemWithTitle:NSArrayObjectAtIndex([theResult fetchRowAsArray], 0)]; } if ([tableDocumentInstance table] != nil && ![(NSString *)[tableDocumentInstance table] isEqualToString:@""]) { @@ -655,19 +653,20 @@ // get fields to be imported for (i = 0; i < [fieldMappingArray count] ; i++ ) { - if ([[fieldMappingArray objectAtIndex:i] intValue] > 0) { + if ([NSArrayObjectAtIndex(fieldMappingArray, i) intValue] > 0) { if ( [fNames length] ) [fNames appendString:@","]; - [fNames appendString:[[[tableSourceInstance fieldNames] objectAtIndex:i] backtickQuotedString]]; + [fNames appendString:[NSArrayObjectAtIndex([tableSourceInstance fieldNames], i) backtickQuotedString]]; } } //import array - for ( i = 0 ; i < [importArray count] ; i++ ) { + long importArrayCount = [importArray count]; + for ( i = 0 ; i < importArrayCount ; i++ ) { //show progress bar - [singleProgressBar setDoubleValue:((i+1)*100/[importArray count])]; - [singleProgressBar displayIfNeeded]; + [singleProgressBar setDoubleValue:((i+1)*100/importArrayCount)]; + // [singleProgressBar displayIfNeeded]; if ( !([importFieldNamesSwitch state] && (i == 0)) ) { //put values in string @@ -675,14 +674,14 @@ for ( j = 0 ; j < [fieldMappingArray count] ; j++ ) { - if ([[fieldMappingArray objectAtIndex:j] intValue] > 0) { + if ([NSArrayObjectAtIndex(fieldMappingArray,j) intValue] > 0) { if ( [fValues length] ) [fValues appendString:@","]; - if ([[[importArray objectAtIndex:i] objectAtIndex:([[fieldMappingArray objectAtIndex:j] intValue] - 1)] isMemberOfClass:[NSNull class]] ) { + if ([[NSArrayObjectAtIndex(importArray, i) objectAtIndex:([NSArrayObjectAtIndex(fieldMappingArray, j) intValue] - 1)] isMemberOfClass:[NSNull class]] ) { [fValues appendString:@"NULL"]; } else { - [fValues appendString:[NSString stringWithFormat:@"'%@'",[mySQLConnection prepareString:[[importArray objectAtIndex:i] objectAtIndex:([[fieldMappingArray objectAtIndex:j] intValue] - 1)]]]]; + [fValues appendString:[NSString stringWithFormat:@"'%@'",[mySQLConnection prepareString:[NSArrayObjectAtIndex(importArray ,i) objectAtIndex:([NSArrayObjectAtIndex(fieldMappingArray ,j) intValue] - 1)]]]]; } } } @@ -694,7 +693,7 @@ fValues]]; if ( ![[mySQLConnection getLastErrorMessage] isEqualToString:@""] ) { - [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"[ERROR in line %d] %@\n", @"error text when reading of csv file gave errors"), (i+1),[mySQLConnection getLastErrorMessage]]]; + [errors appendString:[NSString stringWithFormat:NSLocalizedString(@"[ERROR in line %d] %@\n", @"error text when reading of csv file gave errors"), (i+1),[mySQLConnection getLastErrorMessage]]]; } } } @@ -759,8 +758,8 @@ if (!fieldMappingArray) { fieldMappingArray = [NSMutableArray array]; - for (i = 0; i < [[tableSourceInstance fieldNames] count]; i++) { - if (i < [[importArray objectAtIndex:currentRow] count] && ![[[importArray objectAtIndex:currentRow] objectAtIndex:i] isKindOfClass:[NSNull class]]) { + for (i = 0; i < [[tableSourceInstance fieldNames] count]; i++) { + if (i < [NSArrayObjectAtIndex(importArray, currentRow) count] && ![NSArrayObjectAtIndex(NSArrayObjectAtIndex(importArray, currentRow), i) isKindOfClass:[NSNull class]]) { value = i + 1; } else { value = 0; @@ -785,7 +784,7 @@ if ([[fieldMappingButtonOptions objectAtIndex:i] isNSNull]) { [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, [prefs objectForKey:@"NullValue"]]]; } else { - [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, [fieldMappingButtonOptions objectAtIndex:i]]]; + [fieldMappingButtonOptions replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%i. %@", i+1, NSArrayObjectAtIndex(fieldMappingButtonOptions, i)]]; } } } @@ -855,8 +854,8 @@ // Copy over the selected table names into a table in preparation for iteration for ( i = 0 ; i < [tables count] ; i++ ) { - if ( [[[tables objectAtIndex:i] objectAtIndex:0] boolValue] ) { - [selectedTables addObject:[NSString stringWithString:[[tables objectAtIndex:i] objectAtIndex:1]]]; + if ( [NSArrayObjectAtIndex(NSArrayObjectAtIndex(tables, i), 0) boolValue] ) { + [selectedTables addObject:[NSString stringWithString:NSArrayObjectAtIndex(NSArrayObjectAtIndex(tables, i), 1)]]; } } @@ -899,7 +898,7 @@ lastProgressValue = 0; // Update the progress text and reset the progress bar to indeterminate status while fetching data - tableName = [selectedTables objectAtIndex:i]; + tableName = NSArrayObjectAtIndex(selectedTables, i); [singleProgressText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Table %i of %i (%@): Fetching data...", @"text showing that app is fetching data for table dump"), (i+1), [selectedTables count], tableName]]; [singleProgressText displayIfNeeded]; [singleProgressBar setIndeterminate:YES]; @@ -958,7 +957,7 @@ colCount = [[tableDetails objectForKey:@"columns"] count]; tableColumnNumericStatus = [NSMutableArray arrayWithCapacity:colCount]; for ( j = 0; j < colCount ; j++ ) { - tableColumnTypeGrouping = [[[tableDetails objectForKey:@"columns"] objectAtIndex:j] objectForKey:@"typegrouping"]; + tableColumnTypeGrouping = [NSArrayObjectAtIndex([tableDetails objectForKey:@"columns"], j) objectForKey:@"typegrouping"]; if ([tableColumnTypeGrouping isEqualToString:@"bit"] || [tableColumnTypeGrouping isEqualToString:@"integer"] || [tableColumnTypeGrouping isEqualToString:@"float"]) { [tableColumnNumericStatus addObject:[NSNumber numberWithBool:YES]]; @@ -1212,19 +1211,19 @@ cinfo = [tinfo objectForKey:@"constraints"]; for( int j = 0; j < [cinfo count]; j++ ) { // get the column refs. these can be comma separated. - NSString *ccol = [[cinfo objectAtIndex:j] objectForKey:@"columns"]; - NSString *rcol = [[cinfo objectAtIndex:j] objectForKey:@"ref_columns"]; + NSString *ccol = [NSArrayObjectAtIndex(cinfo, j) objectForKey:@"columns"]; + NSString *rcol = [NSArrayObjectAtIndex(cinfo, j) objectForKey:@"ref_columns"]; NSString *extra = @""; NSArray *tc = [ccol componentsSeparatedByString:@","]; if( [tc count] > 1 ) { extra = @" [ arrowhead=crow, arrowtail=odiamond ]"; - ccol = [tc objectAtIndex:0]; - rcol = [[ccol componentsSeparatedByString:@","] objectAtIndex:0]; + ccol = NSArrayObjectAtIndex(tc, 0); + rcol = NSArrayObjectAtIndex([ccol componentsSeparatedByString:@","], 0); } [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@ %@", tableName, ccol, - [[cinfo objectAtIndex:j] objectForKey:@"ref_table"], + [NSArrayObjectAtIndex(cinfo, j) objectForKey:@"ref_table"], rcol, extra ]]; @@ -1328,7 +1327,7 @@ // Set the progress text [singleProgressText setStringValue:NSLocalizedString(@"Exporting...", @"text showing that app is exporting to text file")]; - [singleProgressText displayIfNeeded]; + // [singleProgressText displayIfNeeded]; // Open progress sheet @@ -1372,7 +1371,7 @@ [csvRow setArray:[queryResult fetchRowAsArray]]; } } else { - [csvRow setArray:[array objectAtIndex:i]]; + [csvRow setArray:NSArrayObjectAtIndex(array, i)]; } [csvString setString:@""]; @@ -1386,14 +1385,14 @@ } // Retrieve the contents of this cell - if ([[csvRow objectAtIndex:j] isKindOfClass:[NSData class]]) { - dataConversionString = [[NSString alloc] initWithData:[csvRow objectAtIndex:j] encoding:tableEncoding]; + if ([NSArrayObjectAtIndex(csvRow, j) isKindOfClass:[NSData class]]) { + dataConversionString = [[NSString alloc] initWithData:NSArrayObjectAtIndex(csvRow, j) encoding:tableEncoding]; if (dataConversionString == nil) - dataConversionString = [[NSString alloc] initWithData:[csvRow objectAtIndex:j] encoding:NSASCIIStringEncoding]; + dataConversionString = [[NSString alloc] initWithData:NSArrayObjectAtIndex(csvRow, j) encoding:NSASCIIStringEncoding]; [csvCell setString:[NSString stringWithString:dataConversionString]]; [dataConversionString release]; } else { - [csvCell setString:[[csvRow objectAtIndex:j] description]]; + [csvCell setString:[NSArrayObjectAtIndex(csvRow, j) description]]; } // For NULL values supplied via an array add the unenclosed null string as set in preferences @@ -1408,12 +1407,12 @@ } else { // Test whether this cell contains a number - if ([[csvRow objectAtIndex:j] isKindOfClass:[NSData class]]) { + if ([NSArrayObjectAtIndex(csvRow, j) isKindOfClass:[NSData class]]) { csvCellIsNumeric = FALSE; // If an array of bools supplying information as to whether the column is numeric has been supplied, use it. } else if (tableColumnNumericStatus != nil) { - csvCellIsNumeric = [[tableColumnNumericStatus objectAtIndex:j] boolValue]; + csvCellIsNumeric = [NSArrayObjectAtIndex(tableColumnNumericStatus, j) boolValue]; // Or fall back to testing numeric content via an NSScanner. } else { diff --git a/Source/TablesList.m b/Source/TablesList.m index 1cd8d8de..fd794cfc 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -33,6 +33,7 @@ #import "CMMCPConnection.h" #import "CMMCPResult.h" #import "SPStringAdditions.h" +#import "SPArrayAdditions.h" #import "RegexKitLite.h" @implementation TablesList @@ -105,21 +106,21 @@ if( [theResult numOfFields] == 1 ) { for( i = 0; i < [theResult numOfRows]; i++ ) { - [tables addObject:[[theResult fetchRowAsArray] objectAtIndex:3]]; - if( [[[theResult fetchRowAsArray] objectAtIndex:4] isEqualToString:@"PROCEDURE"]) { - [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]]; + [tables addObject:NSArrayObjectAtIndex([theResult fetchRowAsArray],3)]; + if( [NSArrayObjectAtIndex([theResult fetchRowAsArray], 4) isEqualToString:@"PROCEDURE"]) { + [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]]; } else { - [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]]; + [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]]; } } } else { for( i = 0; i < [theResult numOfRows]; i++ ) { resultRow = [theResult fetchRowAsArray]; - [tables addObject:[resultRow objectAtIndex:3]]; - if( [[resultRow objectAtIndex:4] isEqualToString:@"PROCEDURE"] ) { - [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]]; + [tables addObject:NSArrayObjectAtIndex(resultRow, 3)]; + if( [NSArrayObjectAtIndex(resultRow, 4) isEqualToString:@"PROCEDURE"] ) { + [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]]; } else { - [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]]; + [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]]; } } } diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj index 831aa666..3e283c81 100644 --- a/sequel-pro.xcodeproj/project.pbxproj +++ b/sequel-pro.xcodeproj/project.pbxproj @@ -1490,7 +1490,7 @@ buildSettings = { ARCHS = "$(ARCHS_STANDARD_32_BIT)"; GCC_C_LANGUAGE_STANDARD = c99; - GCC_OPTIMIZATION_LEVEL = 0; + GCC_OPTIMIZATION_LEVEL = 3; GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; IBC_FLATTEN_NIBS = NO; -- cgit v1.2.3