Skip to content

Commit 229e364

Browse files
committed
Change the Dict.prototype.getRawValues 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`-values to create a temporary `Array` that we finally iterate through at the call-site. Note that the `getRawValues` 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.
1 parent 58996f2 commit 229e364

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

src/core/primitives.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class Dict {
185185

186186
// No dereferencing.
187187
getRawValues() {
188-
return [...this._map.values()];
188+
return this._map.values();
189189
}
190190

191191
getRawEntries() {

test/unit/primitives_spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ describe("primitives", function () {
284284
it("should get all raw values", function () {
285285
// Test direct objects:
286286
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
287-
const rawValues1 = dictWithManyKeys.getRawValues();
287+
const rawValues1 = [...dictWithManyKeys.getRawValues()];
288288

289289
expect(rawValues1.sort()).toEqual(expectedRawValues1);
290290

@@ -305,7 +305,7 @@ describe("primitives", function () {
305305
dict.set("Contents", contentsRef);
306306

307307
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
308-
const rawValues2 = dict.getRawValues();
308+
const rawValues2 = [...dict.getRawValues()];
309309

310310
expect(rawValues2.sort()).toEqual(expectedRawValues2);
311311
});
@@ -380,8 +380,8 @@ describe("primitives", function () {
380380
expect(mergedFontDictKeys).toEqual(["F1"]);
381381
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
382382

383-
const mergedFontDictValues = mergedFontDict.getRawValues();
384-
const mergedSubFontDictValues = mergedSubFontDict.getRawValues();
383+
const mergedFontDictValues = [...mergedFontDict.getRawValues()];
384+
const mergedSubFontDictValues = [...mergedSubFontDict.getRawValues()];
385385

386386
expect(mergedFontDictValues).toEqual(["Local font one"]);
387387
expect(mergedSubFontDictValues).toEqual([

0 commit comments

Comments
 (0)