1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-25 09:38:06 +02:00

Add different code-paths to {CMap, ToUnicodeMap}.charCodeOf depending on length, since Array.prototype.indexOf can be extremely inefficient for very large arrays (issue 8372)

Fixes 8372.
This commit is contained in:
Jonas Jenwald 2017-05-24 17:36:39 +02:00
parent ac942ac657
commit 4ce5e520fb
5 changed files with 138 additions and 8 deletions

View file

@ -283,24 +283,34 @@ var CMap = (function CMapClosure() {
// indices in the *billions*. For such tables we use for..in, which isn't
// ideal because it stringifies the indices for all present elements, but
// it does avoid iterating over every undefined entry.
var map = this._map;
var length = map.length;
var i;
let map = this._map;
let length = map.length;
if (length <= 0x10000) {
for (i = 0; i < length; i++) {
for (let i = 0; i < length; i++) {
if (map[i] !== undefined) {
callback(i, map[i]);
}
}
} else {
for (i in this._map) {
for (let i in map) {
callback(i, map[i]);
}
}
},
charCodeOf(value) {
return this._map.indexOf(value);
// `Array.prototype.indexOf` is *extremely* inefficient for arrays which
// are both very sparse and very large (see issue8372.pdf).
let map = this._map;
if (map.length <= 0x10000) {
return map.indexOf(value);
}
for (let charCode in map) {
if (map[charCode] === value) {
return (charCode | 0);
}
}
return -1;
},
getMap() {