From ef60b2022d50b99e6de78cc301bf71e8b336ae0e Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Tue, 13 Aug 2013 23:49:31 +0000 Subject: Rework table content and custom query data loading and storage for speed increases and lower memory usage: - Add a new SPMySQLStreamingResultStore class to SPMySQL.framework. This class acts as both a result set and a data store for the accompanying data, storing the row information in a custom format in a custom malloc zone. - Amend SPDataStorage to wrap the new class, so original result information is stored in the one location in the custom format. Any edited information is handled by SPDataStorage for clean separation - Rework table content and custom query data data stores to use the new class. This significantly speeds up data loading, resulting in faster data loads if they weren't previously network constrained, or lower CPU usage otherwise. The memory usage is also lowered, with the memory overhead for many small cells being enormously reduced. --- Source/SPDataStorage.h | 68 +++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'Source/SPDataStorage.h') diff --git a/Source/SPDataStorage.h b/Source/SPDataStorage.h index 39d36d5f..d0c1f556 100644 --- a/Source/SPDataStorage.h +++ b/Source/SPDataStorage.h @@ -30,45 +30,54 @@ // // More info at +#import + +@class SPMySQLStreamingResultStore; + /** - * This class provides a storage mechanism intended to represent tabular - * data, in a 2D array. Data can be added and retrieved either directly - * or via NSArrays; internally, C arrays are used to provide speed and - * memory improvements. - * This class is essentially mutable. + * This class wraps a SPMySQLStreamingResultStore, providing an editable + * data store; on a fresh load all data will be proxied from the underlying + * result store, but if cells or rows are edited, mutable rows are stored + * directly. */ -@interface SPDataStorage : NSObject +@interface SPDataStorage : NSObject { - NSUInteger numColumns; - NSUInteger columnPointerByteSize; - NSUInteger numRows, numRowsCapacity; + SPMySQLStreamingResultStore *dataStorage; + NSPointerArray *editedRows; + BOOL *unloadedColumns; - id **dataStorage; + NSUInteger numberOfColumns; } +/* Setting result store */ +- (void) setDataStorage:(SPMySQLStreamingResultStore *) newDataStorage updatingExisting:(BOOL)updateExistingStore; + /* Retrieving rows and cells */ -- (NSMutableArray *) rowContentsAtIndex:(NSUInteger)index; +- (NSMutableArray *) rowContentsAtIndex:(NSUInteger)anIndex; - (id) cellDataAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex; +- (id) cellPreviewAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex previewLength:(NSUInteger)previewLength; +- (BOOL) cellIsNullOrUnloadedAtRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex; /* Adding and amending rows and cells */ -- (void) addRowWithContents:(NSArray *)row; -- (void) insertRowContents:(NSArray *)row atIndex:(NSUInteger)index; -- (void) replaceRowAtIndex:(NSUInteger)index withRowContents:(NSArray *)row; -- (void) replaceObjectInRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex withObject:(id)object; -- (void) removeRowAtIndex:(NSUInteger)index; +- (void) addRowWithContents:(NSMutableArray *)aRow; +- (void) insertRowContents:(NSMutableArray *)aRow atIndex:(NSUInteger)anIndex; +- (void) replaceRowAtIndex:(NSUInteger)anIndex withRowContents:(NSMutableArray *)aRow; +- (void) replaceObjectInRow:(NSUInteger)rowIndex column:(NSUInteger)columnIndex withObject:(id)anObject; +- (void) removeRowAtIndex:(NSUInteger)anIndex; - (void) removeRowsInRange:(NSRange)rangeToRemove; - (void) removeAllRows; +/* Unloaded columns */ +- (void) setColumnAsUnloaded:(NSUInteger)columnIndex; + /* Basic information */ - (NSUInteger) count; -- (void) setColumnCount:(NSUInteger)columnCount; - (NSUInteger) columnCount; +- (BOOL) dataDownloaded; -/* Initialisation and teardown */ -#pragma mark - -- (id) init; -- (void) dealloc; +/* Delegate callback methods */ +- (void)resultStoreDidFinishLoadingData:(SPMySQLStreamingResultStore *)resultStore; @end @@ -91,14 +100,6 @@ static inline void SPDataStorageReplaceRow(SPDataStorage* self, NSUInteger rowIn SPDSReplaceRow(self, @selector(replaceRowAtIndex:withRowContents:), rowIndex, row); } -static inline void SPDataStorageReplaceObjectAtRowAndColumn(SPDataStorage* self, NSUInteger rowIndex, NSUInteger colIndex, id newObject) -{ - typedef void (*SPDSObjectReplaceMethodPtr)(SPDataStorage*, SEL, NSUInteger, NSUInteger, id); - static SPDSObjectReplaceMethodPtr SPDSObjectReplace; - if (!SPDSObjectReplace) SPDSObjectReplace = (SPDSObjectReplaceMethodPtr)[self methodForSelector:@selector(replaceObjectInRow:column:withObject:)]; - SPDSObjectReplace(self, @selector(replaceObjectInRow:column:withObject:), rowIndex, colIndex, newObject); -} - static inline id SPDataStorageObjectAtRowAndColumn(SPDataStorage* self, NSUInteger rowIndex, NSUInteger colIndex) { typedef id (*SPDSObjectFetchMethodPtr)(SPDataStorage*, SEL, NSUInteger, NSUInteger); @@ -106,3 +107,12 @@ static inline id SPDataStorageObjectAtRowAndColumn(SPDataStorage* self, NSUInteg if (!SPDSObjectFetch) SPDSObjectFetch = (SPDSObjectFetchMethodPtr)[self methodForSelector:@selector(cellDataAtRow:column:)]; return SPDSObjectFetch(self, @selector(cellDataAtRow:column:), rowIndex, colIndex); } + +static inline id SPDataStoragePreviewAtRowAndColumn(SPDataStorage* self, NSUInteger rowIndex, NSUInteger colIndex, NSUInteger previewLength) +{ + typedef id (*SPDSPreviewFetchMethodPtr)(SPDataStorage*, SEL, NSUInteger, NSUInteger, NSUInteger); + static SPDSPreviewFetchMethodPtr SPDSPreviewFetch; + if (!SPDSPreviewFetch) SPDSPreviewFetch = (SPDSPreviewFetchMethodPtr)[self methodForSelector:@selector(cellPreviewAtRow:column:previewLength:)]; + return SPDSPreviewFetch(self, @selector(cellPreviewAtRow:column:previewLength:), rowIndex, colIndex, previewLength); +} + -- cgit v1.2.3