Add a makeSet helper, to reduce function creation

This replaces inline `() => new Set()` statements, and also makes some `getOrInsertComputed` calls slightly shorter.
This commit is contained in:
Jonas Jenwald 2026-07-15 13:31:26 +02:00
parent a18b581f00
commit a3a7247366
7 changed files with 16 additions and 11 deletions

View File

@ -13,6 +13,8 @@
* limitations under the License.
*/
import { makeSet } from "../shared/util.js";
const ON_CURVE_POINT = 1 << 0;
const X_SHORT_VECTOR = 1 << 1;
const Y_SHORT_VECTOR = 1 << 2;
@ -756,13 +758,7 @@ function pruneCompositeGlyphCycles(glyfTable, locaEntries, numGlyphs) {
stack.push({ node: next, idx: 0 });
continue;
}
let removeSet = backEdges.get(top.node);
if (!removeSet) {
removeSet = new Set();
backEdges.set(top.node, removeSet);
}
removeSet.add(compIdx);
backEdges.getOrInsertComputed(top.node, makeSet).add(compIdx);
}
}

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
import { assert, unreachable, warn } from "../shared/util.js";
import { assert, makeSet, unreachable, warn } from "../shared/util.js";
import { RefSet, RefSetCache } from "./primitives.js";
class BaseLocalCache {
@ -228,7 +228,7 @@ class GlobalImageCache {
}
shouldCache(ref, pageIndex) {
const pageIndexSet = this._refCache.getOrPutComputed(ref, () => new Set());
const pageIndexSet = this._refCache.getOrPutComputed(ref, makeSet);
pageIndexSet.add(pageIndex);
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {

View File

@ -36,6 +36,7 @@ import {
makeArr,
makeMap,
makeObj,
makeSet,
normalizeUnicode,
OPS,
PasswordException,
@ -131,6 +132,7 @@ globalThis.pdfjsLib = {
makeArr,
makeMap,
makeObj,
makeSet,
MathClamp,
noContextMenu,
normalizeUnicode,
@ -195,6 +197,7 @@ export {
makeArr,
makeMap,
makeObj,
makeSet,
MathClamp,
noContextMenu,
normalizeUnicode,

View File

@ -1135,6 +1135,7 @@ function _isValidExplicitDest(validRef, validName, dest) {
const makeArr = () => [];
const makeMap = () => new Map();
const makeObj = () => Object.create(null);
const makeSet = () => new Set();
// See https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes#browser_compatibility
if (
@ -1197,6 +1198,7 @@ export {
makeArr,
makeMap,
makeObj,
makeSet,
MeshFigureType,
normalizeUnicode,
objectSize,

View File

@ -27,6 +27,7 @@ import {
makeArr,
makeMap,
makeObj,
makeSet,
normalizeUnicode,
OPS,
PasswordException,
@ -115,6 +116,7 @@ const expectedAPI = Object.freeze({
makeArr,
makeMap,
makeObj,
makeSet,
MathClamp,
noContextMenu,
normalizeUnicode,

View File

@ -13,7 +13,7 @@
* limitations under the License.
*/
const { OPS } = globalThis.pdfjsLib || (await import("pdfjs-lib"));
const { makeSet, OPS } = globalThis.pdfjsLib || (await import("pdfjs-lib"));
const opMap = Object.create(null);
for (const key in OPS) {
@ -460,7 +460,7 @@ class Stepper {
for (const [dependentIdx, { dependencies: ownDependencies }] of metadata) {
for (const dependencyIdx of ownDependencies) {
dependents
.getOrInsertComputed(dependencyIdx, () => new Set())
.getOrInsertComputed(dependencyIdx, makeSet)
.add(dependentIdx);
}
}

View File

@ -47,6 +47,7 @@ const {
makeArr,
makeMap,
makeObj,
makeSet,
MathClamp,
noContextMenu,
normalizeUnicode,
@ -111,6 +112,7 @@ export {
makeArr,
makeMap,
makeObj,
makeSet,
MathClamp,
noContextMenu,
normalizeUnicode,