[Pkg-javascript-commits] [pdf.js] 15/174: Right-size the `map` array in PartialEvaluator_readToUnicode

David Prévot taffit at moszumanska.debian.org
Thu Nov 19 18:44:59 UTC 2015


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

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

commit 8d831449abec727b52b148299b4928c032896ef9
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date:   Sat Sep 19 16:54:19 2015 +0200

    Right-size the `map` array in PartialEvaluator_readToUnicode
    
    We can avoid a lot of intermediate resizings, by directly allocating the required number of elements for the `map` array.
---
 src/core/cmap.js       | 8 ++++++++
 src/core/evaluator.js  | 2 +-
 test/unit/cmap_spec.js | 3 +++
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/core/cmap.js b/src/core/cmap.js
index d97c34d..cabc6d2 100644
--- a/src/core/cmap.js
+++ b/src/core/cmap.js
@@ -306,6 +306,10 @@ var CMap = (function CMapClosure() {
       out.length = 1;
     },
 
+    get length() {
+      return this._map.length;
+    },
+
     get isIdentityCMap() {
       if (!(this.name === 'Identity-H' || this.name === 'Identity-V')) {
         return false;
@@ -382,6 +386,10 @@ var IdentityCMap = (function IdentityCMapClosure() {
 
     readCharCode: CMap.prototype.readCharCode,
 
+    get length() {
+      return 0x10000;
+    },
+
     get isIdentityCMap() {
       error('should not access .isIdentityCMap');
     }
diff --git a/src/core/evaluator.js b/src/core/evaluator.js
index 3e0a98d..189130d 100644
--- a/src/core/evaluator.js
+++ b/src/core/evaluator.js
@@ -1380,7 +1380,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
         if (cmap instanceof IdentityCMap) {
           return new IdentityToUnicodeMap(0, 0xFFFF);
         }
-        var map = [];
+        var map = new Array(cmap.length);
         // Convert UTF-16BE
         // NOTE: cmap can be a sparse array, so use forEach instead of for(;;)
         // to iterate over all keys.
diff --git a/test/unit/cmap_spec.js b/test/unit/cmap_spec.js
index f83f92a..f0edf41 100644
--- a/test/unit/cmap_spec.js
+++ b/test/unit/cmap_spec.js
@@ -96,6 +96,7 @@ describe('cmap', function() {
     expect(cmap instanceof CMap).toEqual(true);
     expect(cmap.useCMap).not.toBeNull();
     expect(cmap.builtInCMap).toBeFalsy();
+    expect(cmap.length).toEqual(0x20A7);
     expect(cmap.isIdentityCMap).toEqual(false);
   });
   it('parses cmapname', function() {
@@ -116,6 +117,7 @@ describe('cmap', function() {
     expect(cmap instanceof CMap).toEqual(true);
     expect(cmap.useCMap).toBeNull();
     expect(cmap.builtInCMap).toBeTruthy();
+    expect(cmap.length).toEqual(0x20A7);
     expect(cmap.isIdentityCMap).toEqual(false);
   });
   it('loads built in identity cmap', function() {
@@ -123,6 +125,7 @@ describe('cmap', function() {
                                   { url: cMapUrl, packed: cMapPacked }, null);
     expect(cmap instanceof IdentityCMap).toEqual(true);
     expect(cmap.vertical).toEqual(false);
+    expect(cmap.length).toEqual(0x10000);
     expect(function() { return cmap.isIdentityCMap; }).toThrow(
       new Error('should not access .isIdentityCMap'));
   });

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