From: Robert Konigsberg Date: Sat, 16 Jun 2012 13:41:50 +0000 (-0400) Subject: Two more optimizations: remove default value for predicate, and, use local variable... X-Git-Tag: v1.0.0~238^2^2~6 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=1fdef78645031ce82164e8dc72f71ce53a2ab2f4;p=dygraphs.git Two more optimizations: remove default value for predicate, and, use local variable for nextIdx in advance. --- diff --git a/dygraph-utils.js b/dygraph-utils.js index 0b9d2e5..907069f 100644 --- a/dygraph-utils.js +++ b/dygraph-utils.js @@ -699,8 +699,6 @@ Dygraph.isAndroid = function() { * TODO(konigsberg): add default vlues to start and length. */ Dygraph.createIterator = function(array, start, length, predicate) { - predicate = predicate || function() { return true; }; - var iter = new function() { this.end_ = Math.min(array.length, start + length); this.nextIdx_ = start - 1; // use -1 so initial call to advance works. @@ -724,14 +722,17 @@ Dygraph.createIterator = function(array, start, length, predicate) { return self.peek_; } this.advance_ = function() { - self.nextIdx_++; - while(self.nextIdx_ < self.end_) { - if (predicate(array, self.nextIdx_)) { - self.peek_ = array[self.nextIdx_]; + var nextIdx = self.nextIdx_; + nextIdx++; + while(nextIdx < self.end_) { + if (!predicate || predicate(array, nextIdx)) { + self.peek_ = array[nextIdx]; + self.nextIdx_ = nextIdx; return; } - self.nextIdx_++; + nextIdx++; } + self.nextIdx_ = nextIdx; self.hasNext_ = false; self.peek_ = null; }