From a02978e25e2155e5e6fda12d1a3184fa3bd7987c Mon Sep 17 00:00:00 2001 From: Robert Konigsberg Date: Sat, 16 Jun 2012 10:07:07 -0400 Subject: [PATCH] Optimization: inline isNullOrNan. Also, don't bother calling isNaN just to test NaN itself; x != x is a high-speed replacement. --- dygraph-canvas.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) 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; } } -- 2.7.4