Index: src/XMPPMulticastDelegate.h ================================================================== --- src/XMPPMulticastDelegate.h +++ src/XMPPMulticastDelegate.h @@ -28,11 +28,10 @@ * \brief A class to provide multiple delegates in a single class */ @interface XMPPMulticastDelegate: OFObject { OFDataArray *_delegates; - size_t _handlerIndex; } /** * \brief Adds a delegate which should receive the broadcasts. * Index: src/XMPPMulticastDelegate.m ================================================================== --- src/XMPPMulticastDelegate.m +++ src/XMPPMulticastDelegate.m @@ -22,10 +22,11 @@ #ifdef HAVE_CONFIG_H # include "config.h" #endif +#import #import #import "XMPPMulticastDelegate.h" @implementation XMPPMulticastDelegate @@ -63,72 +64,56 @@ for (i = 0; i < count; i++) { if (items[i] != delegate) continue; [_delegates removeItemAtIndex: i]; - - if (i <= _handlerIndex) - _handlerIndex--; - return; } } - (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; BOOL (*imp)(id, SEL, id) = (BOOL(*)(id, SEL, id)) [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; } - (BOOL)broadcastSelector: (SEL)selector 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; BOOL (*imp)(id, SEL, id, id) = (BOOL(*)(id, SEL, id, id)) [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; } @end