[Pkg-javascript-commits] [pdf.js] 42/161: Avoid allocations in bidi().

David Prévot taffit at moszumanska.debian.org
Sat Apr 19 14:16:22 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 2e93a0cc9878c8493b146e76a08365e9afa3b505
Author: Nicholas Nethercote <nnethercote at mozilla.com>
Date:   Tue Mar 11 21:48:50 2014 -0700

    Avoid allocations in bidi().
---
 src/core/bidi.js | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/core/bidi.js b/src/core/bidi.js
index 6c28dc4..566ed6c 100644
--- a/src/core/bidi.js
+++ b/src/core/bidi.js
@@ -145,6 +145,11 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     this.dir = (vertical ? 'ttb' : (isLTR ? 'ltr' : 'rtl'));
   }
 
+  // These are used in bidi(), which is called frequently. We re-use them on
+  // each call to avoid unnecessary allocations.
+  var chars = [];
+  var types = [];
+
   function bidi(str, startLevel, vertical) {
     var isLTR = true;
     var strLength = str.length;
@@ -153,8 +158,8 @@ var bidi = PDFJS.bidi = (function bidiClosure() {
     }
 
     // Get types and fill arrays
-    var chars = [];
-    var types = [];
+    chars.length = 0;
+    types.length = 0;
     var numBidi = 0;
 
     for (var i = 0; i < strLength; ++i) {

-- 
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