Skip to content

Commit

Permalink
Changing for loops to pre-calculate and cache the iterator length. Co…
Browse files Browse the repository at this point in the history
…uld be better still?
  • Loading branch information
kezabelle committed Mar 15, 2012
1 parent 7a6121a commit 8b502c9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/frontend/modules/hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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);
matched = elements;
}

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); }
Expand All @@ -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;
Expand Down Expand Up @@ -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]);
}
Expand All @@ -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;
}
Expand Down

0 comments on commit 8b502c9

Please sign in to comment.