mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-26 01:58: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:
parent
4df82ad31e
commit
b282814e38
13 changed files with 85 additions and 73 deletions
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Dict, isName, Ref } from "./primitives.js";
|
||||
import { Dict, isName, Name, Ref } from "./primitives.js";
|
||||
import { isString, stringToPDFString, warn } from "../shared/util.js";
|
||||
import { NumberTree } from "./name_number_tree.js";
|
||||
|
||||
|
@ -42,7 +42,7 @@ class StructTreeRoot {
|
|||
return;
|
||||
}
|
||||
roleMapDict.forEach((key, value) => {
|
||||
if (!isName(value)) {
|
||||
if (!(value instanceof Name)) {
|
||||
return;
|
||||
}
|
||||
this.roleMap.set(key, value.name);
|
||||
|
@ -64,7 +64,7 @@ class StructElementNode {
|
|||
|
||||
get role() {
|
||||
const nameObj = this.dict.get("S");
|
||||
const name = isName(nameObj) ? nameObj.name : "";
|
||||
const name = nameObj instanceof Name ? nameObj.name : "";
|
||||
const { root } = this.tree;
|
||||
if (root.roleMap.has(name)) {
|
||||
return root.roleMap.get(name);
|
||||
|
@ -123,7 +123,8 @@ class StructElementNode {
|
|||
pageObjId = pageRef.toString();
|
||||
}
|
||||
|
||||
const type = isName(kidDict.get("Type")) ? kidDict.get("Type").name : null;
|
||||
const type =
|
||||
kidDict.get("Type") instanceof Name ? kidDict.get("Type").name : null;
|
||||
if (type === "MCR") {
|
||||
if (this.tree.pageDict.objId !== pageObjId) {
|
||||
return null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue