1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08: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,8 +283,19 @@ var ToUnicodeMap = (function ToUnicodeMapClosure() {
return this._map[i];
},
charCodeOf(v) {
return this._map.indexOf(v);
charCodeOf(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;
},
amend(map) {