From 7b68737baa518b7ff06b819dd8984b25a49532e2 Mon Sep 17 00:00:00 2001 From: p01 Date: Thu, 15 May 2014 16:06:24 +0200 Subject: [PATCH 1/3] Strict isEOF / ~22% faster on issue2813, from 16.5s to 13.5s --- src/core/parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/parser.js b/src/core/parser.js index 887d37b40..c7e7b184b 100644 --- a/src/core/parser.js +++ b/src/core/parser.js @@ -24,7 +24,7 @@ var EOF = {}; function isEOF(v) { - return (v == EOF); + return (v === EOF); } var Parser = (function ParserClosure() { From cf5ff3d327cd70dc8de63b8db90df491bfb89faa Mon Sep 17 00:00:00 2001 From: p01 Date: Thu, 15 May 2014 16:10:32 +0200 Subject: [PATCH 2/3] Fewer lookups in CanvasGraphics_constructPath --- src/display/canvas.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 646f8a343..3455c3f54 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -983,10 +983,10 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { ctx.lineTo(x, y); break; case OPS.curveTo: - ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], - args[j + 4], args[j + 5]); x = args[j + 4]; y = args[j + 5]; + ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], + x, y); j += 6; break; case OPS.curveTo2: @@ -997,10 +997,9 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { j += 4; break; case OPS.curveTo3: - ctx.bezierCurveTo(args[j], args[j + 1], args[j + 2], args[j + 3], - args[j + 2], args[j + 3]); x = args[j + 2]; y = args[j + 3]; + ctx.bezierCurveTo(args[j], args[j + 1], x, y, x, y); j += 4; break; case OPS.closePath: From 455c6b2d351828a4f4b33737ed1581ab0809587b Mon Sep 17 00:00:00 2001 From: p01 Date: Thu, 15 May 2014 16:25:12 +0200 Subject: [PATCH 3/3] Removed several 'in' operators in canvas.js This gives up to 6x speed improvement on these methods --- src/display/canvas.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/display/canvas.js b/src/display/canvas.js index 3455c3f54..184219809 100644 --- a/src/display/canvas.js +++ b/src/display/canvas.js @@ -1067,21 +1067,21 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { } if (this.pendingEOFill) { - if ('mozFillRule' in this.ctx) { - this.ctx.mozFillRule = 'evenodd'; - this.ctx.fill(); - this.ctx.mozFillRule = 'nonzero'; + if (ctx.mozFillRule !== undefined) { + ctx.mozFillRule = 'evenodd'; + ctx.fill(); + ctx.mozFillRule = 'nonzero'; } else { try { - this.ctx.fill('evenodd'); + ctx.fill('evenodd'); } catch (ex) { // shouldn't really happen, but browsers might think differently - this.ctx.fill(); + ctx.fill(); } } this.pendingEOFill = false; } else { - this.ctx.fill(); + ctx.fill(); } if (needRestore) { @@ -1133,12 +1133,12 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.current.y = this.current.lineY = 0; }, endText: function CanvasGraphics_endText() { - if (!('pendingTextPaths' in this)) { - this.ctx.beginPath(); - return; - } var paths = this.pendingTextPaths; var ctx = this.ctx; + if (paths === undefined) { + ctx.beginPath(); + return; + } ctx.save(); ctx.beginPath(); @@ -1802,7 +1802,7 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { this.ctx = this.groupStack.pop(); // Turn off image smoothing to avoid sub pixel interpolation which can // look kind of blurry for some pdfs. - if ('imageSmoothingEnabled' in this.ctx) { + if (this.ctx.imageSmoothingEnabled !== undefined) { this.ctx.imageSmoothingEnabled = false; } else { this.ctx.mozImageSmoothingEnabled = false; @@ -2144,26 +2144,27 @@ var CanvasGraphics = (function CanvasGraphicsClosure() { // Helper functions consumePath: function CanvasGraphics_consumePath() { + var ctx = this.ctx; if (this.pendingClip) { if (this.pendingClip == EO_CLIP) { - if ('mozFillRule' in this.ctx) { - this.ctx.mozFillRule = 'evenodd'; - this.ctx.clip(); - this.ctx.mozFillRule = 'nonzero'; + if (ctx.mozFillRule !== undefined) { + ctx.mozFillRule = 'evenodd'; + ctx.clip(); + ctx.mozFillRule = 'nonzero'; } else { try { - this.ctx.clip('evenodd'); + ctx.clip('evenodd'); } catch (ex) { // shouldn't really happen, but browsers might think differently - this.ctx.clip(); + ctx.clip(); } } } else { - this.ctx.clip(); + ctx.clip(); } this.pendingClip = null; } - this.ctx.beginPath(); + ctx.beginPath(); }, getSinglePixelWidth: function CanvasGraphics_getSinglePixelWidth(scale) { var inverse = this.ctx.mozCurrentTransformInverse;