[Pkg-javascript-commits] [pdf.js] 176/207: Avoid creating intermediate strings in Util.makeCssRgb().

David Prévot taffit at moszumanska.debian.org
Mon Jul 28 15:36:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository pdf.js.

commit 31c613f0642d3eed677d129f78eb2b0f3707b3f7
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date:   Tue Jul 8 21:31:07 2014 -0700

    Avoid creating intermediate strings in Util.makeCssRgb().
    
    On one example (the Wuppertal map) this avoids the creation of over
    230,000 intermediate strings.
---
 src/shared/util.js | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/shared/util.js b/src/shared/util.js
index 3299816..78e4f59 100644
--- a/src/shared/util.js
+++ b/src/shared/util.js
@@ -560,8 +560,15 @@ var IDENTITY_MATRIX = [1, 0, 0, 1, 0, 0];
 var Util = PDFJS.Util = (function UtilClosure() {
   function Util() {}
 
+  var rgbBuf = ['rgb(', 0, ',', 0, ',', 0, ')'];
+
+  // makeCssRgb() can be called thousands of times. Using |rgbBuf| avoids
+  // creating many intermediate strings.
   Util.makeCssRgb = function Util_makeCssRgb(rgb) {
-    return 'rgb(' + rgb[0] + ',' + rgb[1] + ',' + rgb[2] + ')';
+    rgbBuf[1] = rgb[0];
+    rgbBuf[3] = rgb[1];
+    rgbBuf[5] = rgb[2];
+    return rgbBuf.join('');
   };
 
   // Concatenates two transformation matrices together and returns the result.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git



More information about the Pkg-javascript-commits mailing list