aboutsummaryrefslogtreecommitdiffstats
path: root/content_scripts/mode.coffee
diff options
context:
space:
mode:
authorStephen Blott2015-01-04 14:54:04 +0000
committerStephen Blott2015-01-04 14:54:04 +0000
commit7e4fdac07ffb59c438a17c2c88051064aaab16b5 (patch)
tree36f1e187818bee9448796e2f8a4df4ee9cc312c4 /content_scripts/mode.coffee
parenta5adf7c06128cc963a09acc9960bab1117b55d1a (diff)
downloadvimium-7e4fdac07ffb59c438a17c2c88051064aaab16b5.tar.bz2
Revise handler stack implementation.
The old implementation: - Wasn't actually checking whether handlers had been removed before calling them. - Could end up calling the same handler twice (if a handler was removed further down the stack, and the stack elements moved due the resulting splice. Solution: - Mark elements as removed and check. Set their ids to null. - Don't splice stack. Also, optimisation: - Removing the element at the top of the stack is still O(1). - In Modes, reverse handlers before removing (so, more likely to hit the optimisation above). For the record, the stable stack length at the moment seems to be about 10-12 elements.
Diffstat (limited to 'content_scripts/mode.coffee')
-rw-r--r--content_scripts/mode.coffee4
1 files changed, 3 insertions, 1 deletions
diff --git a/content_scripts/mode.coffee b/content_scripts/mode.coffee
index 10b7bb2a..76b65a12 100644
--- a/content_scripts/mode.coffee
+++ b/content_scripts/mode.coffee
@@ -76,7 +76,9 @@ class Mode
exit: ->
console.log @count, "exit:", @name
- handlerStack.remove handlerId for handlerId in @handlers
+ # We reverse @handlers, here. That way, handlers are popped in the opposite order to that in which they
+ # were pushed.
+ handlerStack.remove handlerId for handlerId in @handlers.reverse()
Mode.modes = Mode.modes.filter (mode) => mode != @
Mode.updateBadge()