From de25b8ea37ae4ff3d9a6212922c5aca4c86b475a Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Fri, 10 Jan 2014 12:01:56 -0800 Subject: [PATCH] Cache specificities --- src/key-binding.coffee | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/key-binding.coffee b/src/key-binding.coffee index d5a12e4ef..1f3ad1d65 100644 --- a/src/key-binding.coffee +++ b/src/key-binding.coffee @@ -8,6 +8,15 @@ module.exports = class KeyBinding @parser: null @currentIndex: 1 + @specificities: null + + @calculateSpecificity: (selector) -> + @specificities ?= {} + value = @specificities[selector] + unless value? + value = specificity(selector) + @specificities[selector] = value + value @normalizeKeystroke: (keystroke) -> normalizedKeystroke = keystroke.split(/\s+/).map (keystroke) => @@ -33,7 +42,7 @@ class KeyBinding @command = command @keystroke = KeyBinding.normalizeKeystroke(keystroke) @selector = selector.replace(/!important/g, '') - @specificity = specificity(selector) + @specificity = KeyBinding.calculateSpecificity(selector) @index = KeyBinding.currentIndex++ matches: (keystroke) ->