mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 08:27:19 +02:00
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:
parent
a18b581f00
commit
a3a7247366
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,6 +47,7 @@ const {
|
||||
makeArr,
|
||||
makeMap,
|
||||
makeObj,
|
||||
makeSet,
|
||||
MathClamp,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
@ -111,6 +112,7 @@ export {
|
||||
makeArr,
|
||||
makeMap,
|
||||
makeObj,
|
||||
makeSet,
|
||||
MathClamp,
|
||||
noContextMenu,
|
||||
normalizeUnicode,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user