mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-04-12 00:04:02 +02:00
Change the Dict.prototype.getKeys method to return an iterator
This method is usually used with loops, and 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 old code, and originally the `Dict` class stored its data in a regular `Object`, hence why the old code was written that way.
This commit is contained in:
parent
40bd73551c
commit
58996f21b2
@ -3398,7 +3398,7 @@ class ButtonWidgetAnnotation extends WidgetAnnotation {
|
||||
? this.data.fieldValue
|
||||
: "Yes";
|
||||
|
||||
const exportValues = this._decodeFormValue(normalAppearance.getKeys());
|
||||
const exportValues = this._decodeFormValue([...normalAppearance.getKeys()]);
|
||||
if (exportValues.length === 0) {
|
||||
exportValues.push("Off", yes);
|
||||
} else if (exportValues.length === 1) {
|
||||
|
||||
@ -180,7 +180,7 @@ class Dict {
|
||||
}
|
||||
|
||||
getKeys() {
|
||||
return [...this._map.keys()];
|
||||
return this._map.keys();
|
||||
}
|
||||
|
||||
// No dereferencing.
|
||||
|
||||
@ -276,7 +276,7 @@ describe("primitives", function () {
|
||||
|
||||
it("should get all key names", function () {
|
||||
const expectedKeys = ["FontFile", "FontFile2", "FontFile3"];
|
||||
const keys = dictWithManyKeys.getKeys();
|
||||
const keys = [...dictWithManyKeys.getKeys()];
|
||||
|
||||
expect(keys.sort()).toEqual(expectedKeys);
|
||||
});
|
||||
@ -337,7 +337,7 @@ describe("primitives", function () {
|
||||
xref: null,
|
||||
dictArray: [dictWithManyKeys, dictWithSizeKey, fontFileDict],
|
||||
});
|
||||
const mergedKeys = mergedDict.getKeys();
|
||||
const mergedKeys = [...mergedDict.getKeys()];
|
||||
|
||||
expect(mergedKeys.sort()).toEqual(expectedKeys);
|
||||
expect(mergedDict.get("FontFile")).toEqual(testFontFile);
|
||||
@ -374,8 +374,8 @@ describe("primitives", function () {
|
||||
expect(mergedFontDict instanceof Dict).toEqual(true);
|
||||
expect(mergedSubFontDict instanceof Dict).toEqual(true);
|
||||
|
||||
const mergedFontDictKeys = mergedFontDict.getKeys();
|
||||
const mergedSubFontDictKeys = mergedSubFontDict.getKeys();
|
||||
const mergedFontDictKeys = [...mergedFontDict.getKeys()];
|
||||
const mergedSubFontDictKeys = [...mergedSubFontDict.getKeys()];
|
||||
|
||||
expect(mergedFontDictKeys).toEqual(["F1"]);
|
||||
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user