aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPArrayAdditions.h
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-03-05 21:52:01 +0000
committerrowanbeentje <rowan@beent.je>2012-03-05 21:52:01 +0000
commitd5e20720cf7f991a691d9a03e7f895211b7c98ad (patch)
tree084208404fd826b53f1754f87ec30bae3d6b35cb /Source/SPArrayAdditions.h
parent0c91f439a5b23e1b5a6d8139eb47aa5694e2925f (diff)
parent69db4915523c4c6cc2d8138a72456cb23f47b7ec (diff)
downloadsequelpro-d5e20720cf7f991a691d9a03e7f895211b7c98ad.tar.gz
sequelpro-d5e20720cf7f991a691d9a03e7f895211b7c98ad.tar.bz2
sequelpro-d5e20720cf7f991a691d9a03e7f895211b7c98ad.zip
- Bring SPMySQL Framework integration branch up to date with trunk
Diffstat (limited to 'Source/SPArrayAdditions.h')
-rw-r--r--Source/SPArrayAdditions.h36
1 files changed, 34 insertions, 2 deletions
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h
index e08bfa33..abeec095 100644
--- a/Source/SPArrayAdditions.h
+++ b/Source/SPArrayAdditions.h
@@ -27,9 +27,41 @@ static inline id NSArrayObjectAtIndex(NSArray *self, NSUInteger i)
return (id)CFArrayGetValueAtIndex((CFArrayRef)self, (long)i);
}
-static inline void NSMutableArrayAddObject(NSArray *self, id anObject)
+/**
+ * Set up a static function to allow fast mutable array insertion using
+ * cached selectors.
+ * At least in 10.7, inserting items into an array at a known point
+ * using NSMutableArray methods appears to be the fastest way of adding
+ * items to a CF/NSMutableArray.
+ */
+static inline void NSMutableArrayInsertObject(NSMutableArray *self, id anObject, NSUInteger anIndex)
{
- CFArrayAppendValue((CFMutableArrayRef)self, anObject);
+ typedef id (*NSMutableArrayInsertObjectPtr)(NSMutableArray*, SEL, id, NSUInteger);
+ static NSMutableArrayInsertObjectPtr cachedMethodPointer;
+ static SEL cachedSelector;
+
+ if (!cachedSelector) cachedSelector = @selector(insertObject:atIndex:);
+ if (!cachedMethodPointer) cachedMethodPointer = (NSMutableArrayInsertObjectPtr)[self methodForSelector:cachedSelector];
+
+ cachedMethodPointer(self, cachedSelector, anObject, anIndex);
+}
+/**
+ * Set up a static function to allow fast mutable array insertion using
+ * cached selectors.
+ * At least in 10.7, adding items to an array using NSMutableArray methods
+ * appears to be the fastest approach to adding items to a CF/NSMutableArray;
+ * only NSMutableArrayInsertObject is faster if the position is known.
+ */
+static inline void NSMutableArrayAddObject(NSMutableArray *self, id anObject)
+{
+ typedef id (*NSMutableArrayAddObjectPtr)(NSMutableArray*, SEL, id);
+ static NSMutableArrayAddObjectPtr cachedMethodPointer;
+ static SEL cachedSelector;
+
+ if (!cachedSelector) cachedSelector = @selector(addObject:);
+ if (!cachedMethodPointer) cachedMethodPointer = (NSMutableArrayAddObjectPtr)[self methodForSelector:cachedSelector];
+
+ cachedMethodPointer(self, cachedSelector, anObject);
}
static inline void NSMutableArrayReplaceObject(NSArray *self, CFIndex idx, id anObject)