mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-09 09:45:42 +02:00
Replace div.dataset
with a WeakMap
in text_layer.js
This patch improves performance by avoiding unnecessary type conversions, which also help the JIT for optimizations. Moreover, this patch fixes issues with the div expansion code where `textScale` would be undefined in a division. Because of the `dataset` usage, other comparisons evaluated to `true` while `false` would have been correct. This makes the expansion mode now work correctly for cases with, for example, each glyph in one div. The polyfill for `WeakMap` has been provided by @yurydelendik.
This commit is contained in:
parent
b10add14f3
commit
b3818d5c36
2 changed files with 117 additions and 65 deletions
|
@ -1442,6 +1442,39 @@ function createPromiseCapability() {
|
|||
//#endif
|
||||
})();
|
||||
|
||||
//#if !MOZCENTRAL
|
||||
(function WeakMapClosure() {
|
||||
if (globalScope.WeakMap) {
|
||||
return;
|
||||
}
|
||||
|
||||
var id = 0;
|
||||
function WeakMap() {
|
||||
this.id = '$weakmap' + (id++);
|
||||
}
|
||||
WeakMap.prototype = {
|
||||
has: function(obj) {
|
||||
return !!Object.getOwnPropertyDescriptor(obj, this.id);
|
||||
},
|
||||
get: function(obj, defaultValue) {
|
||||
return this.has(obj) ? obj[this.id] : defaultValue;
|
||||
},
|
||||
set: function(obj, value) {
|
||||
Object.defineProperty(obj, this.id, {
|
||||
value: value,
|
||||
enumerable: false,
|
||||
configurable: true
|
||||
});
|
||||
},
|
||||
delete: function(obj) {
|
||||
delete obj[this.id];
|
||||
}
|
||||
};
|
||||
|
||||
globalScope.WeakMap = WeakMap;
|
||||
})();
|
||||
//#endif
|
||||
|
||||
var StatTimer = (function StatTimerClosure() {
|
||||
function rpad(str, pad, length) {
|
||||
while (str.length < length) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue