Skip to content

Commit dfab0cd

Browse files
committed
Remove a superfluous ivar and the unholy intermingling of UI and data code it has caused (part of #2770)
1 parent e1b881b commit dfab0cd

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

Diff for: Source/SPCustomQuery.h

-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@
160160

161161
SPDataStorage *resultData;
162162
pthread_mutex_t resultDataLock;
163-
NSInteger resultDataCount;
164163
NSArray *cqColumnDefinition;
165164
NSString *lastExecutedQuery;
166165
NSInteger editedRow;

Diff for: Source/SPCustomQuery.m

+18-23
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#import "SPAppController.h"
6262
#import "SPBundleHTMLOutputController.h"
6363
#endif
64+
#import "SPFunctions.h"
6465

6566
#import <pthread.h>
6667
#import <SPMySQL/SPMySQL.h>
@@ -884,7 +885,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
884885
(long)totalAffectedRows
885886
];
886887
}
887-
if(resultDataCount) {
888+
if([resultData count]) {
888889
// we were running a query that returns a result set (ie. SELECT).
889890
// TODO: mysql_query() returns as soon as the first result row is found (which might be pretty soon when using indexes / not doing aggregations)
890891
// and that makes our query time measurement pretty useless (see #264)
@@ -905,7 +906,7 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
905906
#endif
906907

907908
// If no results were returned, redraw the empty table and post notifications before returning.
908-
if ( !resultDataCount ) {
909+
if ( ![resultData count] ) {
909910
[customQueryView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:YES];
910911

911912
// Notify any listeners that the query has completed
@@ -931,8 +932,6 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
931932
return;
932933
}
933934

934-
[[customQueryView onMainThread] reloadData];
935-
936935
// Restore the result view origin if appropriate
937936
if (!NSEqualRects(selectionViewportToRestore, NSZeroRect)) {
938937

@@ -976,12 +975,12 @@ - (void)performQueriesTask:(NSDictionary *)taskArguments
976975
*/
977976
- (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
978977
{
979-
980-
// Remove all items from the table
981-
resultDataCount = 0;
982-
[customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:YES];
983978
pthread_mutex_lock(&resultDataLock);
984-
[resultData removeAllRows];
979+
// Remove all items from the table
980+
SPMainQSync(^{
981+
[resultData removeAllRows];
982+
[customQueryView noteNumberOfRowsChanged];
983+
});
985984

986985
// Add the new store
987986
[resultData setDataStorage:theResultStore updatingExisting:NO];
@@ -994,11 +993,8 @@ - (void)updateResultStore:(SPMySQLStreamingResultStore *)theResultStore
994993
[[self onMainThread] initQueryLoadTimer];
995994

996995
[resultData awaitDataDownloaded];
997-
998-
// If the final column autoresize wasn't performed, perform it
999-
if (queryLoadLastRowCount < 200) [[self onMainThread] autosizeColumns];
1000-
1001-
[customQueryView performSelectorOnMainThread:@selector(noteNumberOfRowsChanged) withObject:nil waitUntilDone:NO];
996+
997+
// Any further UI updates are the responsibility of the timer callback
1002998
}
1003999

10041000
/**
@@ -1488,8 +1484,8 @@ - (void) clearQueryLoadTimer
14881484
*/
14891485
- (void) queryLoadUpdate:(NSTimer *)theTimer
14901486
{
1491-
resultDataCount = [resultData count];
1492-
1487+
NSUInteger resultDataCount = [resultData count];
1488+
14931489
if (queryLoadTimerTicksSinceLastUpdate < queryLoadInterfaceUpdateInterval) {
14941490
queryLoadTimerTicksSinceLastUpdate++;
14951491
return;
@@ -1501,7 +1497,7 @@ - (void) queryLoadUpdate:(NSTimer *)theTimer
15011497

15021498
// Check whether a table update is required, based on whether new rows are
15031499
// available to display.
1504-
if (resultDataCount == (NSInteger)queryLoadLastRowCount) {
1500+
if (resultDataCount == queryLoadLastRowCount) {
15051501
return;
15061502
}
15071503

@@ -1548,7 +1544,7 @@ - (NSArray *)currentResult
15481544
*/
15491545
- (NSUInteger)currentResultRowCount
15501546
{
1551-
return resultDataCount;
1547+
return [resultData count];
15521548
}
15531549

15541550
/**
@@ -2077,7 +2073,7 @@ - (void)saveCellValue:(id)anObject forTableColumn:(NSTableColumn *)aTableColumn
20772073
*/
20782074
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView
20792075
{
2080-
return (aTableView == customQueryView) ? (resultData == nil) ? 0 : resultDataCount : 0;
2076+
return (aTableView == customQueryView) ? (resultData == nil) ? 0 : [resultData count] : 0;
20812077
}
20822078

20832079
/**
@@ -2102,7 +2098,7 @@ - (void)tableView:(SPCopyTable *)aTableView willDisplayCell:(id)cell forTableCol
21022098
if (isWorking) {
21032099
pthread_mutex_lock(&resultDataLock);
21042100

2105-
if (rowIndex < resultDataCount && columnIndex < [resultData columnCount]) {
2101+
if (SPIntS2U(rowIndex) < [resultData count] && columnIndex < [resultData columnCount]) {
21062102
showCellAsGray = [resultData cellIsNullOrUnloadedAtRow:rowIndex column:columnIndex];
21072103
} else {
21082104
showCellAsGray = YES;
@@ -2403,7 +2399,7 @@ - (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(SPTextAndLinkC
24032399
// cases.
24042400
if (isWorking) {
24052401
pthread_mutex_lock(&resultDataLock);
2406-
if (row < resultDataCount && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
2402+
if (SPIntS2U(row) < [resultData count] && (NSUInteger)[[aTableColumn identifier] integerValue] < [resultData columnCount]) {
24072403
theValue = [[SPDataStorageObjectAtRowAndColumn(resultData, row, [[aTableColumn identifier] integerValue]) copy] autorelease];
24082404
}
24092405
pthread_mutex_unlock(&resultDataLock);
@@ -3769,7 +3765,6 @@ - (id)init
37693765
#endif
37703766

37713767
// init tableView's data source
3772-
resultDataCount = 0;
37733768
resultData = [[SPDataStorage alloc] init];
37743769
editedRow = -1;
37753770

@@ -4022,7 +4017,7 @@ - (id)_resultDataItemAtRow:(NSInteger)row columnIndex:(NSUInteger)column preserv
40224017
if (isWorking) {
40234018
pthread_mutex_lock(&resultDataLock);
40244019

4025-
if (row < resultDataCount && column < [resultData columnCount]) {
4020+
if (SPIntS2U(row) < [resultData count] && column < [resultData columnCount]) {
40264021
value = SPDataStoragePreviewAtRowAndColumn(resultData, row, column, 150);
40274022
}
40284023

0 commit comments

Comments
 (0)