static bool removeListenerFromVector(EventListenerVector& listeners, EventListener& listener, bool useCapture) { size_t indexOfRemovedListener = findListener(listeners, listener, useCapture); if (UNLIKELY(indexOfRemovedListener == notFound)) return false; listeners[indexOfRemovedListener]->markAsRemoved(); listeners.remove(indexOfRemovedListener); return true; }
bool EventTarget::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) { EventTargetData* d = eventTargetData(); if (!d) return false; EventListenerMap::iterator result = d->eventListenerMap.find(eventType); if (result == d->eventListenerMap.end()) return false; EventListenerVector* entry = result->second; RegisteredEventListener registeredListener(listener, useCapture); size_t index = entry->find(registeredListener); if (index == notFound) return false; entry->remove(index); if (entry->isEmpty()) { delete entry; d->eventListenerMap.remove(result); } // Notify firing events planning to invoke the listener at 'index' that // they have one less listener to invoke. for (size_t i = 0; i < d->firingEventIterators.size(); ++i) { if (eventType != d->firingEventIterators[i].eventType) continue; if (index >= d->firingEventIterators[i].end) continue; --d->firingEventIterators[i].end; if (index <= d->firingEventIterators[i].iterator) --d->firingEventIterators[i].iterator; } return true; }