fix: determine insertion function up-front

This commit is contained in:
shirakaba
2022-12-21 16:16:47 +09:00
parent 8b5efc1346
commit 569b1f2de3

View File

@@ -208,9 +208,13 @@ export class DOMEvent implements Event {
return recycledEventPath;
}
// Determining the function up-front (rather than inside the loop) saves
// 50 nanoseconds per dispatchTo() call.
const insert = path === 'capture' ? recycledEventPath.unshift.bind(recycledEventPath) : recycledEventPath.push.bind(recycledEventPath);
let nextResponder = responder.parent;
while (nextResponder) {
path === 'capture' ? recycledEventPath.unshift(nextResponder) : recycledEventPath.push(nextResponder);
insert(nextResponder);
// TODO: decide whether to walk up from Page to Frame, and whether
// to then walk from Frame to Application or something.