Permalink
Browse files

Adding a method to GCDMulticastDelegate for a tiny performance improv…

…ement.
  • Loading branch information...
1 parent 01e9cf2 commit 9e3171e502449e2d30175d9de09eab681da60ff7 @robbiehanson committed Jul 13, 2012
View
@@ -1837,7 +1837,7 @@ - (void)sendIQ:(XMPPIQ *)iq withTag:(long)tag
SEL selector = @selector(xmppStream:willSendIQ:);
- if ([multicastDelegate countForSelector:selector] == 0)
+ if (![multicastDelegate hasDelegateThatRespondsToSelector:selector])
{
// None of the delegates implement the method.
// Use a shortcut.
@@ -1907,7 +1907,7 @@ - (void)sendMessage:(XMPPMessage *)message withTag:(long)tag
SEL selector = @selector(xmppStream:willSendMessage:);
- if ([multicastDelegate countForSelector:selector] == 0)
+ if (![multicastDelegate hasDelegateThatRespondsToSelector:selector])
{
// None of the delegates implement the method.
// Use a shortcut.
@@ -1977,7 +1977,7 @@ - (void)sendPresence:(XMPPPresence *)presence withTag:(long)tag
SEL selector = @selector(xmppStream:willSendPresence:);
- if ([multicastDelegate countForSelector:selector] == 0)
+ if (![multicastDelegate hasDelegateThatRespondsToSelector:selector])
{
// None of the delegates implement the method.
// Use a shortcut.
@@ -2814,7 +2814,7 @@ - (void)handleBinding:(NSXMLElement *)response
{
SEL selector = @selector(xmppStream:alternativeResourceForConflictingResource:);
- if ([multicastDelegate countForSelector:selector] == 0)
+ if (![multicastDelegate hasDelegateThatRespondsToSelector:selector])
{
// None of the delegates implement the method.
// Use a shortcut.
@@ -692,7 +692,7 @@ - (void)collectMyCapabilities
SEL selector = @selector(xmppCapabilities:collectingMyCapabilities:);
- if ([multicastDelegate countForSelector:selector] == 0)
+ if (![multicastDelegate hasDelegateThatRespondsToSelector:selector])
{
// None of the delegates implement the method.
// Use a shortcut.
@@ -36,6 +36,8 @@
- (NSUInteger)countOfClass:(Class)aClass;
- (NSUInteger)countForSelector:(SEL)aSelector;
+- (BOOL)hasDelegateThatRespondsToSelector:(SEL)aSelector;
+
- (GCDMulticastDelegateEnumerator *)delegateEnumerator;
@end
@@ -232,6 +232,25 @@ - (NSUInteger)countForSelector:(SEL)aSelector
return count;
}
+- (BOOL)hasDelegateThatRespondsToSelector:(SEL)aSelector
+{
+ for (GCDMulticastDelegateNode *node in delegateNodes)
+ {
+ id nodeDelegate = node.delegate;
+ #if __has_feature(objc_arc_weak) && !TARGET_OS_IPHONE
+ if (nodeDelegate == [NSNull null])
+ nodeDelegate = node.unsafeDelegate;
+ #endif
+
+ if ([nodeDelegate respondsToSelector:aSelector])
+ {
+ return YES;
+ }
+ }
+
+ return NO;
+}
+
- (GCDMulticastDelegateEnumerator *)delegateEnumerator
{
return [[GCDMulticastDelegateEnumerator alloc] initFromDelegateNodes:delegateNodes];

0 comments on commit 9e3171e

Please sign in to comment.