1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 10:47:59 +01:00

Microoptimize some stuff that turns out to need micro-optimizing.

This commit is contained in:
Kris Maglione
2015-12-20 21:28:54 -08:00
parent 28fe4afc4e
commit 0ba81bfc3f
3 changed files with 62 additions and 39 deletions

View File

@@ -1,4 +1,4 @@
// Copyright (c) 2008-2014 Kris Maglione <maglione.k at Gmail>
// Copyright (c) 2008-2015 Kris Maglione <maglione.k at Gmail>
//
// This work is licensed for reuse under an MIT license. Details are
// given in the LICENSE.txt file included with this file.
@@ -14,7 +14,8 @@ var ProcessorStack = Class("ProcessorStack", {
this.buffer = "";
this.events = [];
events.dbg("STACK " + mode);
if (events.debug)
events.dbg("STACK " + mode);
let main = { __proto__: mode.main, params: mode.params };
this.modes = Ary([mode.params.keyModes,
@@ -53,7 +54,6 @@ var ProcessorStack = Class("ProcessorStack", {
}),
notify: function () {
events.dbg("NOTIFY()");
events.keyEvents = [];
events.processor = null;
if (!this.execute(undefined, true)) {
@@ -71,8 +71,9 @@ var ProcessorStack = Class("ProcessorStack", {
},
execute: function execute(result, force) {
events.dbg("EXECUTE(" + this._result(result) + ", " + force + ") events:" + this.events.length
+ " processors:" + this.processors.length + " actions:" + this.actions.length);
if (events.debug)
events.dbg("EXECUTE(" + this._result(result) + ", " + force + ") events:" + this.events.length
+ " processors:" + this.processors.length + " actions:" + this.actions.length);
let length = 1;
@@ -91,7 +92,8 @@ var ProcessorStack = Class("ProcessorStack", {
while (callable(action)) {
length = action.eventLength;
action = dactyl.trapErrors(action);
events.dbg("ACTION RES: " + length + " " + this._result(action));
if (events.debug)
events.dbg("ACTION RES: " + length + " " + this._result(action));
}
if (action !== Events.PASS)
break;
@@ -131,7 +133,8 @@ var ProcessorStack = Class("ProcessorStack", {
// pass the event.
result = Events.PASS;
events.dbg("RESULT: " + length + " " + this._result(result) + "\n\n");
if (events.debug)
events.dbg("RESULT: " + length + " " + this._result(result) + "\n\n");
if (result !== Events.PASS || this.events.length > 1)
if (result !== Events.ABORT || !this.events[0].isReplay)
@@ -140,7 +143,7 @@ var ProcessorStack = Class("ProcessorStack", {
if (result === Events.PASS_THROUGH || result === Events.PASS && this.passUnknown)
events.passing = true;
if (result === Events.PASS_THROUGH && this.keyEvents.length)
if (events.debug && result === Events.PASS_THROUGH && this.keyEvents.length)
events.dbg("PASS_THROUGH:\n\t" + this.keyEvents.map(e => [e.type, DOM.Event.stringify(e)]).join("\n\t"));
if (result === Events.PASS_THROUGH)
@@ -148,10 +151,12 @@ var ProcessorStack = Class("ProcessorStack", {
else {
let list = this.events.filter(e => e.defaultPrevented && !e.dactylDefaultPrevented);
if (result === Events.PASS)
events.dbg("PASS THROUGH: " + list.slice(0, length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
if (list.length > length)
events.dbg("REFEED: " + list.slice(length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
if (events.debug) {
if (result === Events.PASS)
events.dbg("PASS THROUGH: " + list.slice(0, length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
if (list.length > length)
events.dbg("REFEED: " + list.slice(length).filter(e => e.type === "keypress").map(DOM.Event.bound.stringify));
}
if (result === Events.PASS)
events.feedevents(null, list.slice(0, length), { skipmap: true, isMacro: true, isReplay: true });
@@ -176,14 +181,16 @@ var ProcessorStack = Class("ProcessorStack", {
let actions = [];
let processors = [];
events.dbg("PROCESS(" + key + ") skipmap: " + event.skipmap + " macro: " + event.isMacro + " replay: " + event.isReplay);
if (events.debug)
events.dbg("PROCESS(" + key + ") skipmap: " + event.skipmap + " macro: " + event.isMacro + " replay: " + event.isReplay);
for (let input of this.processors) {
let res = input.process(event);
if (res !== Events.ABORT)
var result = res;
events.dbg("RES: " + input + " " + this._result(res));
if (events.debug)
events.dbg("RES: " + input + " " + this._result(res));
if (res === Events.KILL)
break;
@@ -197,9 +204,11 @@ var ProcessorStack = Class("ProcessorStack", {
processors.push(res);
}
events.dbg("RESULT: " + event.defaultPrevented + " " + this._result(result));
events.dbg("ACTIONS: " + actions.length + " " + this.actions.length);
events.dbg("PROCESSORS:", processors, "\n");
if (events.debug) {
events.dbg("RESULT: " + event.defaultPrevented + " " + this._result(result));
events.dbg("ACTIONS: " + actions.length + " " + this.actions.length);
events.dbg("PROCESSORS:", processors, "\n");
}
this._actions = actions;
this.actions = actions.concat(this.actions);