From 73593d4bf35290f2045707c47d3b14c0a46916ac Mon Sep 17 00:00:00 2001 From: Ferhat Date: Fri, 11 Nov 2016 16:18:00 -0800 Subject: [PATCH] perf(platform-browser): cache plugin resolution in the EventManager closes #12824 --- .../platform-browser/src/dom/events/event_manager.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/@angular/platform-browser/src/dom/events/event_manager.ts b/modules/@angular/platform-browser/src/dom/events/event_manager.ts index 349ea70b20..deb6d12edb 100644 --- a/modules/@angular/platform-browser/src/dom/events/event_manager.ts +++ b/modules/@angular/platform-browser/src/dom/events/event_manager.ts @@ -20,6 +20,7 @@ export const EVENT_MANAGER_PLUGINS: OpaqueToken = new OpaqueToken('EventManagerP @Injectable() export class EventManager { private _plugins: EventManagerPlugin[]; + private _eventNameToPlugin = new Map(); constructor(@Inject(EVENT_MANAGER_PLUGINS) plugins: EventManagerPlugin[], private _zone: NgZone) { plugins.forEach(p => p.manager = this); @@ -40,10 +41,16 @@ export class EventManager { /** @internal */ _findPluginFor(eventName: string): EventManagerPlugin { + const plugin = this._eventNameToPlugin.get(eventName); + if (plugin) { + return plugin; + } + const plugins = this._plugins; for (let i = 0; i < plugins.length; i++) { const plugin = plugins[i]; if (plugin.supports(eventName)) { + this._eventNameToPlugin.set(eventName, plugin); return plugin; } }