1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +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:
Jonas Jenwald 2022-02-21 12:45:00 +01:00
parent 4df82ad31e
commit b282814e38
13 changed files with 85 additions and 73 deletions

View file

@ -14,12 +14,12 @@
*/
import { assert, FormatError, ImageKind, info, warn } from "../shared/util.js";
import { isName, Name } from "./primitives.js";
import { BaseStream } from "./base_stream.js";
import { ColorSpace } from "./colorspace.js";
import { DecodeStream } from "./decode_stream.js";
import { JpegStream } from "./jpeg_stream.js";
import { JpxImage } from "./jpx.js";
import { Name } from "./primitives.js";
/**
* Decode and clamp a value. The formula is different from the spec because we
@ -95,7 +95,7 @@ class PDFImage {
const dict = image.dict;
const filter = dict.get("F", "Filter");
if (isName(filter)) {
if (filter instanceof Name) {
switch (filter.name) {
case "JPXDecode":
const jpxImage = new JpxImage();