From 8b502c96873f708732eeeb2f9c43cd9553f29245 Mon Sep 17 00:00:00 2001 From: Keryn Knight Date: Thu, 15 Mar 2012 20:47:56 +0000 Subject: [PATCH] Changing for loops to pre-calculate and cache the iterator length. Could be better still? --- src/frontend/modules/hint.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/frontend/modules/hint.js b/src/frontend/modules/hint.js index 81e47478..3db58aa2 100644 --- a/src/frontend/modules/hint.js +++ b/src/frontend/modules/hint.js @@ -18,7 +18,7 @@ var Hint = (function() { // Get all visible elements var elems = document.body.querySelectorAll('a, input:not([type=hidden]), textarea, select, button, *[onclick]'); - for (var i=0; i < elems.length; i++) { + for (var i = 0, j = elems.length; i < j; i++) { if (isElementVisible(elems[i])) { elements.push(elems[i]); } } setHintIndex(elements); @@ -26,7 +26,7 @@ var Hint = (function() { } function removeHighlightBox(/* Boolean */ create_after_remove) { - for (var i = 0; i < elements.length; i++) { elements[i].removeAttribute(highlight); } + for (var i = 0, j = elements.length; i < j; i++) { elements[i].removeAttribute(highlight); } var div = document.getElementById('__vim_hint_highlight'); if (div) { document.body.removeChild(div); } @@ -44,7 +44,7 @@ var Hint = (function() { var win_top = window.scrollY / Zoom.current(); var win_left = window.scrollX / Zoom.current(); var frag = document.createDocumentFragment(); - for (var i = 0; i < elems.length; i++) { //TODO need refactor + for (var i = 0, j = elems.length; i < j; i++) { //TODO need refactor var elem = elems[i]; var pos = elem.getBoundingClientRect(); var elem_top = win_top + pos.top; @@ -158,7 +158,7 @@ var Hint = (function() { selected = 0; matched = []; - for (var i=0; i < elements.length; i++) { + for (var i = 0, j = elements.length; i < j; i++) { if (hintMatch(elements[i], i)) { matched.push(elements[i]); } @@ -167,7 +167,7 @@ var Hint = (function() { setHintIndex(matched); if (isCtrlAcceptKey(key)) { - for (var i=0; i < matched.length; i++) { + for (var i = 0, j = matched.length; i < j; i++) { execSelect(matched[i]); new_tab = true; }