mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 17:48:07 +02:00
Prefer instanceof Name
rather than calling isName()
with one argument
Unless you actually need to check that something is both a `Name` and also of the *correct* type, using `instanceof Name` 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 `isName` helper function for where it makes sense.
This commit is contained in:
parent
4df82ad31e
commit
b282814e38
13 changed files with 85 additions and 73 deletions
|
@ -20,7 +20,7 @@ import {
|
|||
unreachable,
|
||||
warn,
|
||||
} from "../shared/util.js";
|
||||
import { Cmd, EOF, isCmd, isName } from "./primitives.js";
|
||||
import { Cmd, EOF, isCmd, Name } from "./primitives.js";
|
||||
import { BaseStream } from "./base_stream.js";
|
||||
import { Lexer } from "./parser.js";
|
||||
import { MissingDataException } from "./core_utils.js";
|
||||
|
@ -901,7 +901,7 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||
|
||||
function parseCMapName(cMap, lexer) {
|
||||
const obj = lexer.getObj();
|
||||
if (isName(obj) && isString(obj.name)) {
|
||||
if (obj instanceof Name && isString(obj.name)) {
|
||||
cMap.name = obj.name;
|
||||
}
|
||||
}
|
||||
|
@ -913,7 +913,7 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||
const obj = lexer.getObj();
|
||||
if (obj === EOF) {
|
||||
break;
|
||||
} else if (isName(obj)) {
|
||||
} else if (obj instanceof Name) {
|
||||
if (obj.name === "WMode") {
|
||||
parseWMode(cMap, lexer);
|
||||
} else if (obj.name === "CMapName") {
|
||||
|
@ -925,7 +925,7 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||
case "endcmap":
|
||||
break objLoop;
|
||||
case "usecmap":
|
||||
if (isName(previous)) {
|
||||
if (previous instanceof Name) {
|
||||
embeddedUseCMap = previous.name;
|
||||
}
|
||||
break;
|
||||
|
@ -1024,7 +1024,7 @@ const CMapFactory = (function CMapFactoryClosure() {
|
|||
const fetchBuiltInCMap = params.fetchBuiltInCMap;
|
||||
const useCMap = params.useCMap;
|
||||
|
||||
if (isName(encoding)) {
|
||||
if (encoding instanceof Name) {
|
||||
return createBuiltInCMap(encoding.name, fetchBuiltInCMap);
|
||||
} else if (encoding instanceof BaseStream) {
|
||||
const parsedCMap = await parseCMap(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue