From: Robert Konigsberg Date: Sat, 16 Jun 2012 14:07:07 +0000 (-0400) Subject: Optimization: inline isNullOrNan. Also, don't bother calling isNaN just to test NaN... X-Git-Tag: v1.0.0~238^2^2~5 X-Git-Url: https://adrianiainlam.tk/git/?a=commitdiff_plain;h=a02978e25e2155e5e6fda12d1a3184fa3bd7987c;p=dygraphs.git Optimization: inline isNullOrNan. Also, don't bother calling isNaN just to test NaN itself; x != x is a high-speed replacement. --- diff --git a/dygraph-canvas.js b/dygraph-canvas.js index bdca590..4a29848 100644 --- a/dygraph-canvas.js +++ b/dygraph-canvas.js @@ -781,10 +781,6 @@ DygraphCanvasRenderer.prototype._drawSeries = function( ctx, iter, strokeWidth, pointSize, drawPoints, drawGapPoints, stepPlot, strategy) { - var isNullOrNaN = function(x) { - return (x === null || isNaN(x)); - }; - var prevCanvasX = null; var prevCanvasY = null; var nextCanvasY = null; @@ -797,7 +793,7 @@ DygraphCanvasRenderer.prototype._drawSeries = function( while(iter.hasNext()) { point = iter.next(); - if (isNullOrNaN(point.canvasy)) { + if (point.canvasy === null || point.canvasy != point.canvasy) { if (stepPlot && prevCanvasX !== null) { // Draw a horizontal line to the start of the missing data strategy.startSegment(); @@ -807,12 +803,15 @@ DygraphCanvasRenderer.prototype._drawSeries = function( prevCanvasX = prevCanvasY = null; } else { nextCanvasY = iter.hasNext() ? iter.peek().canvasy : null; - isIsolated = (!prevCanvasX && isNullOrNaN(nextCanvasY)); + // TODO: we calculate isNullOrNaN for this point, and the next, and then, when + // we iterate, test for isNullOrNaN again. Why bother? + var isNextCanvasYNullOrNaN = nextCanvasY === null || nextCanvasY != nextCanvasY; + isIsolated = (!prevCanvasX && isNextCanvasYNullOrNaN); if (drawGapPoints) { // Also consider a point to be "isolated" if it's adjacent to a // null point, excluding the graph edges. if ((!first && !prevCanvasX) || - (iter.hasNext() && isNullOrNaN(nextCanvasY))) { + (iter.hasNext() && isNextCanvasYNullOrNaN)) { isIsolated = true; } }