aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-09-24 11:36:57 +0000
committerstuconnolly <stuart02@gmail.com>2012-09-24 11:36:57 +0000
commit4004ca9491c5a4b49b97440aa36f6f1070488b0e (patch)
treecad20d313f0aac9e8e7153a28fb459c87b1bdb4b
parent9fdd0153492ebdae259e0514d9028d3b6f261b81 (diff)
downloadsequelpro-4004ca9491c5a4b49b97440aa36f6f1070488b0e.tar.gz
sequelpro-4004ca9491c5a4b49b97440aa36f6f1070488b0e.tar.bz2
sequelpro-4004ca9491c5a4b49b97440aa36f6f1070488b0e.zip
Implement fast enumeration for PostgresKit's result class. Based on SPMySQL's implementation by Rowan.
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresResult.h2
-rw-r--r--Frameworks/PostgresKit/Source/FLXPostgresResult.m30
2 files changed, 31 insertions, 1 deletions
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.h b/Frameworks/PostgresKit/Source/FLXPostgresResult.h
index 168f8f15..6f10c3e5 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresResult.h
+++ b/Frameworks/PostgresKit/Source/FLXPostgresResult.h
@@ -30,7 +30,7 @@ typedef enum
}
FLXPostgresResultRowType;
-@interface FLXPostgresResult : NSObject
+@interface FLXPostgresResult : NSObject <NSFastEnumeration>
{
void *_result;
void **_typeHandlers;
diff --git a/Frameworks/PostgresKit/Source/FLXPostgresResult.m b/Frameworks/PostgresKit/Source/FLXPostgresResult.m
index 06950a3b..02375650 100644
--- a/Frameworks/PostgresKit/Source/FLXPostgresResult.m
+++ b/Frameworks/PostgresKit/Source/FLXPostgresResult.m
@@ -175,6 +175,36 @@
}
#pragma mark -
+#pragma mark Fast enumeration implementation
+
+- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)stackbuf count:(NSUInteger)len
+{
+ if (state->state >= _numberOfRows) return 0;
+
+ if (state->state != _row) [self seekToRow:state->state];
+
+ // Determine how many objects to return - 128, len, or all items remaining
+ NSUInteger itemsToReturn = 128;
+
+ if (len < 128) itemsToReturn = len;
+
+ if (_numberOfRows - state->state < itemsToReturn) {
+ itemsToReturn = (unsigned long)_numberOfRows - state->state;
+ }
+
+ for (NSUInteger i = 0; i < itemsToReturn; i++)
+ {
+ stackbuf[i] = [self rowAsType:_defaultRowType];
+ }
+
+ state->state += itemsToReturn;
+ state->itemsPtr = stackbuf;
+ state->mutationsPtr = (unsigned long *)self;
+
+ return itemsToReturn;
+}
+
+#pragma mark -
#pragma mark Private API
/**