mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-25 17:45:48 +02:00
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.
This commit is contained in:
parent
58996f21b2
commit
229e3642be
@ -185,7 +185,7 @@ class Dict {
|
|||||||
|
|
||||||
// No dereferencing.
|
// No dereferencing.
|
||||||
getRawValues() {
|
getRawValues() {
|
||||||
return [...this._map.values()];
|
return this._map.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
getRawEntries() {
|
getRawEntries() {
|
||||||
|
|||||||
@ -284,7 +284,7 @@ describe("primitives", function () {
|
|||||||
it("should get all raw values", function () {
|
it("should get all raw values", function () {
|
||||||
// Test direct objects:
|
// Test direct objects:
|
||||||
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
|
const expectedRawValues1 = [testFontFile, testFontFile2, testFontFile3];
|
||||||
const rawValues1 = dictWithManyKeys.getRawValues();
|
const rawValues1 = [...dictWithManyKeys.getRawValues()];
|
||||||
|
|
||||||
expect(rawValues1.sort()).toEqual(expectedRawValues1);
|
expect(rawValues1.sort()).toEqual(expectedRawValues1);
|
||||||
|
|
||||||
@ -305,7 +305,7 @@ describe("primitives", function () {
|
|||||||
dict.set("Contents", contentsRef);
|
dict.set("Contents", contentsRef);
|
||||||
|
|
||||||
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
|
const expectedRawValues2 = [contentsRef, resourcesRef, typeName];
|
||||||
const rawValues2 = dict.getRawValues();
|
const rawValues2 = [...dict.getRawValues()];
|
||||||
|
|
||||||
expect(rawValues2.sort()).toEqual(expectedRawValues2);
|
expect(rawValues2.sort()).toEqual(expectedRawValues2);
|
||||||
});
|
});
|
||||||
@ -380,8 +380,8 @@ describe("primitives", function () {
|
|||||||
expect(mergedFontDictKeys).toEqual(["F1"]);
|
expect(mergedFontDictKeys).toEqual(["F1"]);
|
||||||
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
|
expect(mergedSubFontDictKeys).toEqual(["F1", "F2", "F3"]);
|
||||||
|
|
||||||
const mergedFontDictValues = mergedFontDict.getRawValues();
|
const mergedFontDictValues = [...mergedFontDict.getRawValues()];
|
||||||
const mergedSubFontDictValues = mergedSubFontDict.getRawValues();
|
const mergedSubFontDictValues = [...mergedSubFontDict.getRawValues()];
|
||||||
|
|
||||||
expect(mergedFontDictValues).toEqual(["Local font one"]);
|
expect(mergedFontDictValues).toEqual(["Local font one"]);
|
||||||
expect(mergedSubFontDictValues).toEqual([
|
expect(mergedSubFontDictValues).toEqual([
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user