mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-07-25 16:37:22 +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.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { makeSet } from "../shared/util.js";
|
||||||
|
|
||||||
const ON_CURVE_POINT = 1 << 0;
|
const ON_CURVE_POINT = 1 << 0;
|
||||||
const X_SHORT_VECTOR = 1 << 1;
|
const X_SHORT_VECTOR = 1 << 1;
|
||||||
const Y_SHORT_VECTOR = 1 << 2;
|
const Y_SHORT_VECTOR = 1 << 2;
|
||||||
@ -756,13 +758,7 @@ function pruneCompositeGlyphCycles(glyfTable, locaEntries, numGlyphs) {
|
|||||||
stack.push({ node: next, idx: 0 });
|
stack.push({ node: next, idx: 0 });
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
backEdges.getOrInsertComputed(top.node, makeSet).add(compIdx);
|
||||||
let removeSet = backEdges.get(top.node);
|
|
||||||
if (!removeSet) {
|
|
||||||
removeSet = new Set();
|
|
||||||
backEdges.set(top.node, removeSet);
|
|
||||||
}
|
|
||||||
removeSet.add(compIdx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* 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";
|
import { RefSet, RefSetCache } from "./primitives.js";
|
||||||
|
|
||||||
class BaseLocalCache {
|
class BaseLocalCache {
|
||||||
@ -228,7 +228,7 @@ class GlobalImageCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
shouldCache(ref, pageIndex) {
|
shouldCache(ref, pageIndex) {
|
||||||
const pageIndexSet = this._refCache.getOrPutComputed(ref, () => new Set());
|
const pageIndexSet = this._refCache.getOrPutComputed(ref, makeSet);
|
||||||
pageIndexSet.add(pageIndex);
|
pageIndexSet.add(pageIndex);
|
||||||
|
|
||||||
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
if (pageIndexSet.size < GlobalImageCache.NUM_PAGES_THRESHOLD) {
|
||||||
|
|||||||
@ -36,6 +36,7 @@ import {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
PasswordException,
|
PasswordException,
|
||||||
@ -131,6 +132,7 @@ globalThis.pdfjsLib = {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
MathClamp,
|
MathClamp,
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
@ -195,6 +197,7 @@ export {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
MathClamp,
|
MathClamp,
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
|
|||||||
@ -1135,6 +1135,7 @@ function _isValidExplicitDest(validRef, validName, dest) {
|
|||||||
const makeArr = () => [];
|
const makeArr = () => [];
|
||||||
const makeMap = () => new Map();
|
const makeMap = () => new Map();
|
||||||
const makeObj = () => Object.create(null);
|
const makeObj = () => Object.create(null);
|
||||||
|
const makeSet = () => new Set();
|
||||||
|
|
||||||
// See https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes#browser_compatibility
|
// See https://developer.mozilla.org/en-US/docs/Web/API/Blob/bytes#browser_compatibility
|
||||||
if (
|
if (
|
||||||
@ -1197,6 +1198,7 @@ export {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
MeshFigureType,
|
MeshFigureType,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
objectSize,
|
objectSize,
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
OPS,
|
OPS,
|
||||||
PasswordException,
|
PasswordException,
|
||||||
@ -115,6 +116,7 @@ const expectedAPI = Object.freeze({
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
MathClamp,
|
MathClamp,
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
|
|||||||
@ -13,7 +13,7 @@
|
|||||||
* limitations under the License.
|
* 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);
|
const opMap = Object.create(null);
|
||||||
for (const key in OPS) {
|
for (const key in OPS) {
|
||||||
@ -460,7 +460,7 @@ class Stepper {
|
|||||||
for (const [dependentIdx, { dependencies: ownDependencies }] of metadata) {
|
for (const [dependentIdx, { dependencies: ownDependencies }] of metadata) {
|
||||||
for (const dependencyIdx of ownDependencies) {
|
for (const dependencyIdx of ownDependencies) {
|
||||||
dependents
|
dependents
|
||||||
.getOrInsertComputed(dependencyIdx, () => new Set())
|
.getOrInsertComputed(dependencyIdx, makeSet)
|
||||||
.add(dependentIdx);
|
.add(dependentIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,6 +47,7 @@ const {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
MathClamp,
|
MathClamp,
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
@ -111,6 +112,7 @@ export {
|
|||||||
makeArr,
|
makeArr,
|
||||||
makeMap,
|
makeMap,
|
||||||
makeObj,
|
makeObj,
|
||||||
|
makeSet,
|
||||||
MathClamp,
|
MathClamp,
|
||||||
noContextMenu,
|
noContextMenu,
|
||||||
normalizeUnicode,
|
normalizeUnicode,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user