Skip to content

Commit 50d66d7

Browse files
committed
Use the Dict.prototype.getRawEntries method more
This changes a number of loops currently using `Dict.prototype.{getKeys, getRaw}`, since it should be a tiny bit more efficient to use an iterator directly rather than first iterating through `Map`-keys to create a temporary `Array` that we finally iterate through at the call-site. Note that the `getKeys` method is much older than `getRawEntries`, and originally the `Dict` class stored its data in a regular `Object`, hence why the old code was written that way.
1 parent 68cca32 commit 50d66d7

3 files changed

Lines changed: 8 additions & 9 deletions

File tree

src/core/annotation.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2228,9 +2228,9 @@ class WidgetAnnotation extends Annotation {
22282228
}
22292229

22302230
const dict = new Dict(xref);
2231-
for (const key of originalDict.getKeys()) {
2231+
for (const [key, rawVal] of originalDict.getRawEntries()) {
22322232
if (key !== "AP") {
2233-
dict.set(key, originalDict.getRaw(key));
2233+
dict.set(key, rawVal);
22342234
}
22352235
}
22362236
if (flags !== undefined) {
@@ -2442,8 +2442,8 @@ class WidgetAnnotation extends Annotation {
24422442

24432443
if (this._fieldResources.mergedResources.has("Font")) {
24442444
const oldFont = this._fieldResources.mergedResources.get("Font");
2445-
for (const key of newFont.getKeys()) {
2446-
oldFont.set(key, newFont.getRaw(key));
2445+
for (const [key, rawVal] of newFont.getRawEntries()) {
2446+
oldFont.set(key, rawVal);
24472447
}
24482448
} else {
24492449
this._fieldResources.mergedResources.set("Font", newFont);

src/core/core_utils.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,15 +459,14 @@ function collectActions(xref, dict, eventType) {
459459
if (!(additionalActions instanceof Dict)) {
460460
continue;
461461
}
462-
for (const key of additionalActions.getKeys()) {
462+
for (const [key, rawActionDict] of additionalActions.getRawEntries()) {
463463
const action = eventType[key];
464464
if (!action) {
465465
continue;
466466
}
467-
const actionDict = additionalActions.getRaw(key);
468467
const parents = new RefSet();
469468
const list = [];
470-
_collectJS(actionDict, xref, list, parents);
469+
_collectJS(rawActionDict, xref, list, parents);
471470
if (list.length > 0) {
472471
actions[action] = list;
473472
}

src/core/primitives.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,8 @@ class Dict {
312312

313313
clone() {
314314
const dict = new Dict(this.xref);
315-
for (const key of this.getKeys()) {
316-
dict.set(key, this.getRaw(key));
315+
for (const [key, rawVal] of this.getRawEntries()) {
316+
dict.set(key, rawVal);
317317
}
318318
return dict;
319319
}

0 commit comments

Comments
 (0)