Remove the objectSize helper function

Given that Maps are used a lot more these days, this helper function is now used very sparingly and inlining the necessary code seems reasonable.

*Note:* Once [this proposal](https://github.com/tc39/proposal-object-keys-length) makes it into Firefox, we should be able to simplify all `Object.keys(...).length` call-sites.
This commit is contained in:
Jonas Jenwald 2026-07-24 12:49:44 +02:00
parent fe0b880926
commit 675e9219b5
5 changed files with 7 additions and 14 deletions

View File

@ -18,7 +18,6 @@ import {
assert, assert,
BaseException, BaseException,
makeArr, makeArr,
objectSize,
Util, Util,
warn, warn,
} from "../shared/util.js"; } from "../shared/util.js";
@ -491,7 +490,7 @@ function collectActions(xref, dict, eventType) {
actions.Action = list; actions.Action = list;
} }
} }
return objectSize(actions) > 0 ? actions : null; return Object.keys(actions).length ? actions : null;
} }
const XMLEntities = { const XMLEntities = {

View File

@ -21,7 +21,6 @@ import {
InvalidPDFException, InvalidPDFException,
isArrayEqual, isArrayEqual,
makeArr, makeArr,
objectSize,
PageActionEventType, PageActionEventType,
RenderingIntentFlag, RenderingIntentFlag,
shadow, shadow,
@ -1986,7 +1985,7 @@ class PDFDocument {
await Promise.all(allPromises); await Promise.all(allPromises);
return { return {
allFields: objectSize(allFields) > 0 ? allFields : null, allFields: Object.keys(allFields).length ? allFields : null,
orphanFields, orphanFields,
}; };
}); });

View File

@ -615,10 +615,6 @@ function stringToBytes(str) {
return bytes; return bytes;
} }
function objectSize(obj) {
return Object.keys(obj).length;
}
class FeatureTest { class FeatureTest {
static get isLittleEndian() { static get isLittleEndian() {
const buffer8 = new Uint8Array(4); const buffer8 = new Uint8Array(4);
@ -1209,7 +1205,6 @@ export {
makeSet, makeSet,
MeshFigureType, MeshFigureType,
normalizeUnicode, normalizeUnicode,
objectSize,
OPS, OPS,
PageActionEventType, PageActionEventType,
PasswordException, PasswordException,

View File

@ -22,7 +22,6 @@ import {
ImageKind, ImageKind,
InvalidPDFException, InvalidPDFException,
isNodeJS, isNodeJS,
objectSize,
OPS, OPS,
PasswordException, PasswordException,
PasswordResponses, PasswordResponses,
@ -4143,7 +4142,7 @@ describe("api", function () {
const { items, styles, lang } = await page.getTextContent(); const { items, styles, lang } = await page.getTextContent();
expect(items.length).toEqual(15); expect(items.length).toEqual(15);
expect(objectSize(styles)).toEqual(5); expect(Object.keys(styles).length).toEqual(5);
expect(lang).toEqual("en"); expect(lang).toEqual("en");
const text = mergeText(items); const text = mergeText(items);

View File

@ -15,7 +15,6 @@
import { AppOptions, OptionKind } from "../../web/app_options.js"; import { AppOptions, OptionKind } from "../../web/app_options.js";
import { BasePreferences } from "../../web/preferences.js"; import { BasePreferences } from "../../web/preferences.js";
import { objectSize } from "../../src/shared/util.js";
describe("AppOptions", function () { describe("AppOptions", function () {
it("checks that getAll returns data, for every OptionKind", function () { it("checks that getAll returns data, for every OptionKind", function () {
@ -32,7 +31,7 @@ describe("AppOptions", function () {
expect(typeof kind).toEqual("number"); expect(typeof kind).toEqual("number");
const options = AppOptions.getAll(kind); const options = AppOptions.getAll(kind);
expect(objectSize(options)).toBeGreaterThan(0); expect(Object.keys(options).length).toBeGreaterThan(0);
} }
}); });
@ -43,7 +42,9 @@ describe("AppOptions", function () {
const MAX_NUMBER_OF_PREFS = 50; const MAX_NUMBER_OF_PREFS = 50;
const options = AppOptions.getAll(OptionKind.PREFERENCE); const options = AppOptions.getAll(OptionKind.PREFERENCE);
expect(objectSize(options)).toBeLessThanOrEqual(MAX_NUMBER_OF_PREFS); expect(Object.keys(options).length).toBeLessThanOrEqual(
MAX_NUMBER_OF_PREFS
);
}); });
}); });