mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Avoid an allocation in readCharCode().
readCharCode() returns two values, and currently allocates a length-2 array on every call to do so. This change makes it instead us a passed-in object which can be reused. This tiny change reduces the total JS allocations done for the document in Mozilla bug 992125 by 4.2%.
This commit is contained in:
parent
0e4d9061b2
commit
61e6b576d4
3 changed files with 21 additions and 16 deletions
|
@ -281,7 +281,7 @@ var CMap = (function CMapClosure() {
|
|||
return this._map;
|
||||
},
|
||||
|
||||
readCharCode: function(str, offset) {
|
||||
readCharCode: function(str, offset, out) {
|
||||
var c = 0;
|
||||
var codespaceRanges = this.codespaceRanges;
|
||||
var codespaceRangesLen = this.codespaceRanges.length;
|
||||
|
@ -295,12 +295,14 @@ var CMap = (function CMapClosure() {
|
|||
var low = codespaceRange[k++];
|
||||
var high = codespaceRange[k++];
|
||||
if (c >= low && c <= high) {
|
||||
return [c, n + 1];
|
||||
out.charcode = c;
|
||||
out.length = n + 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [0, 1];
|
||||
out.charcode = 0;
|
||||
out.length = 1;
|
||||
}
|
||||
};
|
||||
return CMap;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue