mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58:06 +02:00
Prefer instanceof Dict
rather than calling isDict()
with one argument
Unless you actually need to check that something is both a `Dict` and also of the *correct* type, using `instanceof Dict` directly should be a tiny bit more efficient since it avoids one function call and an unnecessary `undefined` check. This patch uses ESLint to enforce this, since we obviously still want to keep the `isDict` helper function for where it makes sense.
This commit is contained in:
parent
67b658e8d5
commit
4df82ad31e
18 changed files with 83 additions and 93 deletions
|
@ -35,16 +35,7 @@ import {
|
|||
warn,
|
||||
} from "../shared/util.js";
|
||||
import { CMapFactory, IdentityCMap } from "./cmap.js";
|
||||
import {
|
||||
Cmd,
|
||||
Dict,
|
||||
EOF,
|
||||
isDict,
|
||||
isName,
|
||||
Name,
|
||||
Ref,
|
||||
RefSet,
|
||||
} from "./primitives.js";
|
||||
import { Cmd, Dict, EOF, isName, Name, Ref, RefSet } from "./primitives.js";
|
||||
import { ErrorFont, Font } from "./fonts.js";
|
||||
import { FontFlags, getFontType } from "./fonts_utils.js";
|
||||
import {
|
||||
|
@ -1042,7 +1033,7 @@ class PartialEvaluator {
|
|||
gStateObj.push([key, false]);
|
||||
break;
|
||||
}
|
||||
if (isDict(value)) {
|
||||
if (value instanceof Dict) {
|
||||
isSimpleGState = false;
|
||||
|
||||
promise = promise.then(() => {
|
||||
|
@ -1162,7 +1153,7 @@ class PartialEvaluator {
|
|||
}
|
||||
|
||||
font = xref.fetchIfRef(fontRef);
|
||||
if (!isDict(font)) {
|
||||
if (!(font instanceof Dict)) {
|
||||
return errorFont();
|
||||
}
|
||||
|
||||
|
@ -1190,7 +1181,7 @@ class PartialEvaluator {
|
|||
fontID = `f${fontRef.toString()}`;
|
||||
}
|
||||
|
||||
if (hash && isDict(descriptor)) {
|
||||
if (hash && descriptor instanceof Dict) {
|
||||
if (!descriptor.fontAliases) {
|
||||
descriptor.fontAliases = Object.create(null);
|
||||
}
|
||||
|
@ -1493,7 +1484,7 @@ class PartialEvaluator {
|
|||
if (isName(contentProperties)) {
|
||||
const properties = resources.get("Properties");
|
||||
optionalContent = properties.get(contentProperties.name);
|
||||
} else if (isDict(contentProperties)) {
|
||||
} else if (contentProperties instanceof Dict) {
|
||||
optionalContent = contentProperties;
|
||||
} else {
|
||||
throw new FormatError("Optional content properties malformed.");
|
||||
|
@ -1521,7 +1512,7 @@ class PartialEvaluator {
|
|||
const optionalContentGroups = optionalContent.get("OCGs");
|
||||
if (
|
||||
Array.isArray(optionalContentGroups) ||
|
||||
isDict(optionalContentGroups)
|
||||
optionalContentGroups instanceof Dict
|
||||
) {
|
||||
const groupIds = [];
|
||||
if (Array.isArray(optionalContentGroups)) {
|
||||
|
@ -3133,7 +3124,7 @@ class PartialEvaluator {
|
|||
if (includeMarkedContent) {
|
||||
flushTextContentItem();
|
||||
let mcid = null;
|
||||
if (isDict(args[1])) {
|
||||
if (args[1] instanceof Dict) {
|
||||
mcid = args[1].get("MCID");
|
||||
}
|
||||
textContent.items.push({
|
||||
|
@ -3197,7 +3188,7 @@ class PartialEvaluator {
|
|||
if (properties.composite) {
|
||||
// CIDSystemInfo helps to match CID to glyphs
|
||||
const cidSystemInfo = dict.get("CIDSystemInfo");
|
||||
if (isDict(cidSystemInfo)) {
|
||||
if (cidSystemInfo instanceof Dict) {
|
||||
properties.cidSystemInfo = {
|
||||
registry: stringToPDFString(cidSystemInfo.get("Registry")),
|
||||
ordering: stringToPDFString(cidSystemInfo.get("Ordering")),
|
||||
|
@ -3222,7 +3213,7 @@ class PartialEvaluator {
|
|||
let encoding;
|
||||
if (dict.has("Encoding")) {
|
||||
encoding = dict.get("Encoding");
|
||||
if (isDict(encoding)) {
|
||||
if (encoding instanceof Dict) {
|
||||
baseEncodingName = encoding.get("BaseEncoding");
|
||||
baseEncodingName = isName(baseEncodingName)
|
||||
? baseEncodingName.name
|
||||
|
@ -3784,7 +3775,7 @@ class PartialEvaluator {
|
|||
hash.update(encoding.name);
|
||||
} else if (encoding instanceof Ref) {
|
||||
hash.update(encoding.toString());
|
||||
} else if (isDict(encoding)) {
|
||||
} else if (encoding instanceof Dict) {
|
||||
for (const entry of encoding.getRawValues()) {
|
||||
if (isName(entry)) {
|
||||
hash.update(entry.name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue