From 2d96126a44a8325f1ff1c6e9d5a694c9335e60ad Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Wed, 5 Jun 2013 21:00:13 +0200 Subject: [PATCH] XMPPMulticastDelegate: Iterate over a copy of the delegates array --- src/XMPPMulticastDelegate.h | 1 - src/XMPPMulticastDelegate.m | 37 +++++++++++-------------------------- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/XMPPMulticastDelegate.h b/src/XMPPMulticastDelegate.h index 0516343..c7dbbc8 100644 --- a/src/XMPPMulticastDelegate.h +++ b/src/XMPPMulticastDelegate.h @@ -30,7 +30,6 @@ @interface XMPPMulticastDelegate: OFObject { OFDataArray *_delegates; - size_t _handlerIndex; } /** diff --git a/src/XMPPMulticastDelegate.m b/src/XMPPMulticastDelegate.m index aa9ccd0..fb2ede6 100644 --- a/src/XMPPMulticastDelegate.m +++ b/src/XMPPMulticastDelegate.m @@ -24,6 +24,7 @@ # include "config.h" #endif +#import #import #import "XMPPMulticastDelegate.h" @@ -65,10 +66,6 @@ continue; [_delegates removeItemAtIndex: i]; - - if (i <= _handlerIndex) - _handlerIndex--; - return; } } @@ -76,12 +73,13 @@ - (BOOL)broadcastSelector: (SEL)selector withObject: (id)object { - size_t count = [_delegates count]; - id *items = [_delegates items]; + OFDataArray *currentDelegates = [_delegates copy]; + id *items = [currentDelegates items]; + size_t i, count = [currentDelegates count]; BOOL handled = NO; - for (_handlerIndex = 0; _handlerIndex < count; _handlerIndex++) { - id responder = items[_handlerIndex]; + for (i = 0; i < count; i++) { + id responder = items[i]; if (![responder respondsToSelector: selector]) continue; @@ -90,13 +88,6 @@ [responder methodForSelector: selector]; handled |= imp(responder, selector, object); - - /* - * Update count and items, since the handler might have changed - * them. - */ - count = [_delegates count]; - items = [_delegates items]; } return handled; @@ -106,12 +97,13 @@ withObject: (id)object1 withObject: (id)object2 { - size_t count = [_delegates count]; - id *items = [_delegates items]; + OFDataArray *currentDelegates = [_delegates copy]; + id *items = [currentDelegates items]; + size_t i, count = [currentDelegates count]; BOOL handled = NO; - for (_handlerIndex = 0; _handlerIndex < count; _handlerIndex++) { - id responder = items[_handlerIndex]; + for (i = 0; i < count; i++) { + id responder = items[i]; if (![responder respondsToSelector: selector]) continue; @@ -120,13 +112,6 @@ [responder methodForSelector: selector]; handled |= imp(responder, selector, object1, object2); - - /* - * Update count and items, since the handler might have changed - * them. - */ - count = [_delegates count]; - items = [_delegates items]; } return handled;