Merge pull request #14751 from Snuffleupagus/isLittleEndian-isEvalSupported

Re-factor the `isLittleEndian`/`isEvalSupported` caching
This commit is contained in:
Tim van der Meij 2022-04-08 20:02:23 +02:00 committed by GitHub
commit 106b69a101
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 26 deletions

View File

@ -209,20 +209,16 @@ class Catalog {
return null; return null;
} }
const markInfo = Object.assign(Object.create(null), { const markInfo = {
Marked: false, Marked: false,
UserProperties: false, UserProperties: false,
Suspects: false, Suspects: false,
}); };
for (const key in markInfo) { for (const key in markInfo) {
if (!obj.has(key)) {
continue;
}
const value = obj.get(key); const value = obj.get(key);
if (typeof value !== "boolean") { if (typeof value === "boolean") {
continue; markInfo[key] = value;
} }
markInfo[key] = value;
} }
return markInfo; return markInfo;

View File

@ -15,9 +15,9 @@
import { Dict, Ref } from "./primitives.js"; import { Dict, Ref } from "./primitives.js";
import { import {
FeatureTest,
FormatError, FormatError,
info, info,
IsEvalSupportedCached,
shadow, shadow,
unreachable, unreachable,
} from "../shared/util.js"; } from "../shared/util.js";
@ -438,7 +438,7 @@ class PDFFunction {
const parser = new PostScriptParser(lexer); const parser = new PostScriptParser(lexer);
const code = parser.parse(); const code = parser.parse();
if (isEvalSupported && IsEvalSupportedCached.value) { if (isEvalSupported && FeatureTest.isEvalSupported) {
const compiled = new PostScriptCompiler().compile(code, domain, range); const compiled = new PostScriptCompiler().compile(code, domain, range);
if (compiled) { if (compiled) {
// Compiled function consists of simple expressions such as addition, // Compiled function consists of simple expressions such as addition,

View File

@ -14,11 +14,11 @@
*/ */
import { import {
FeatureTest,
FONT_IDENTITY_MATRIX, FONT_IDENTITY_MATRIX,
IDENTITY_MATRIX, IDENTITY_MATRIX,
ImageKind, ImageKind,
info, info,
IsLittleEndianCached,
OPS, OPS,
shadow, shadow,
TextRenderingMode, TextRenderingMode,
@ -702,7 +702,7 @@ function putBinaryImageData(ctx, imgData, transferMaps = null) {
const dest32DataLength = dest32.length; const dest32DataLength = dest32.length;
const fullSrcDiff = (width + 7) >> 3; const fullSrcDiff = (width + 7) >> 3;
let white = 0xffffffff; let white = 0xffffffff;
let black = IsLittleEndianCached.value ? 0xff000000 : 0x000000ff; let black = FeatureTest.isLittleEndian ? 0xff000000 : 0x000000ff;
if (transferMapGray) { if (transferMapGray) {
if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) { if (transferMapGray[0] === 0xff && transferMapGray[0xff] === 0) {

View File

@ -16,7 +16,7 @@
import { import {
assert, assert,
bytesToString, bytesToString,
IsEvalSupportedCached, FeatureTest,
shadow, shadow,
string32, string32,
unreachable, unreachable,
@ -455,7 +455,7 @@ class FontFaceObject {
} }
// If we can, compile cmds into JS for MAXIMUM SPEED... // If we can, compile cmds into JS for MAXIMUM SPEED...
if (this.isEvalSupported && IsEvalSupportedCached.value) { if (this.isEvalSupported && FeatureTest.isEvalSupported) {
const jsBuf = []; const jsBuf = [];
for (const current of cmds) { for (const current of cmds) {
const args = current.args !== undefined ? current.args.join(",") : ""; const args = current.args !== undefined ? current.args.join(",") : "";

View File

@ -682,11 +682,6 @@ function isLittleEndian() {
const view32 = new Uint32Array(buffer8.buffer, 0, 1); const view32 = new Uint32Array(buffer8.buffer, 0, 1);
return view32[0] === 1; return view32[0] === 1;
} }
const IsLittleEndianCached = {
get value() {
return shadow(this, "value", isLittleEndian());
},
};
// Checks if it's possible to eval JS expressions. // Checks if it's possible to eval JS expressions.
function isEvalSupported() { function isEvalSupported() {
@ -697,11 +692,16 @@ function isEvalSupported() {
return false; return false;
} }
} }
const IsEvalSupportedCached = {
get value() { class FeatureTest {
return shadow(this, "value", isEvalSupported()); static get isLittleEndian() {
}, return shadow(this, "isLittleEndian", isLittleEndian());
}; }
static get isEvalSupported() {
return shadow(this, "isEvalSupported", isEvalSupported());
}
}
const hexNumbers = [...Array(256).keys()].map(n => const hexNumbers = [...Array(256).keys()].map(n =>
n.toString(16).padStart(2, "0") n.toString(16).padStart(2, "0")
@ -1103,6 +1103,7 @@ export {
createValidAbsoluteUrl, createValidAbsoluteUrl,
DocumentActionEventType, DocumentActionEventType,
escapeString, escapeString,
FeatureTest,
FONT_IDENTITY_MATRIX, FONT_IDENTITY_MATRIX,
FontType, FontType,
FormatError, FormatError,
@ -1115,8 +1116,6 @@ export {
isArrayBuffer, isArrayBuffer,
isArrayEqual, isArrayEqual,
isAscii, isAscii,
IsEvalSupportedCached,
IsLittleEndianCached,
MissingPDFException, MissingPDFException,
objectFromMap, objectFromMap,
objectSize, objectSize,