aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Blott2016-04-09 06:32:51 +0100
committerStephen Blott2016-04-09 06:32:53 +0100
commitac9543d9017fbb56e670c0728173432a879d4d13 (patch)
tree5a4fadadac39275ca54f5b61cfbb73ea92b1bdf3
parentc8ca94bd83bb1a651cd4efdaef41906f46004ee5 (diff)
downloadvimium-ac9543d9017fbb56e670c0728173432a879d4d13.tar.bz2
Minor performance tweak.
Two minor tweaks: 1. Do not use ".indexOf()" three times for each comparison; do it just once. 2. Check the common case (no match) first. These are very minor performance tweaks; but, with global link hints, we pay this cost n times (for n frames).
-rw-r--r--content_scripts/link_hints.coffee15
1 files changed, 8 insertions, 7 deletions
diff --git a/content_scripts/link_hints.coffee b/content_scripts/link_hints.coffee
index 08c5cd9b..6ea10377 100644
--- a/content_scripts/link_hints.coffee
+++ b/content_scripts/link_hints.coffee
@@ -506,14 +506,15 @@ class FilterHints
for searchWord in searchWords
linkWordScores =
for linkWord, idx in linkWords
- if linkWord == searchWord
- if idx == 0 then 8 else 6
- else if linkWord.startsWith searchWord
- if idx == 0 then 4 else 2
- else if 0 <= linkWord.indexOf searchWord
- 1
+ position = linkWord.indexOf searchWord
+ if position < 0
+ 0 # No match.
+ else if position == 0 and searchWord.length == linkWord.length
+ if idx == 0 then 8 else 6 # Whole-word match.
+ else if position == 0
+ if idx == 0 then 4 else 2 # Match at the start of a word.
else
- 0
+ 1 # 0 < position; other match.
Math.max linkWordScores...
if 0 in searchWordScores