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
|
@ -13,7 +13,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { isDict, isName, Ref } from "./primitives.js";
|
||||
import { Dict, isName, Ref } from "./primitives.js";
|
||||
import { isString, stringToPDFString, warn } from "../shared/util.js";
|
||||
import { NumberTree } from "./name_number_tree.js";
|
||||
|
||||
|
@ -38,7 +38,7 @@ class StructTreeRoot {
|
|||
|
||||
readRoleMap() {
|
||||
const roleMapDict = this.dict.get("RoleMap");
|
||||
if (!isDict(roleMapDict)) {
|
||||
if (!(roleMapDict instanceof Dict)) {
|
||||
return;
|
||||
}
|
||||
roleMapDict.forEach((key, value) => {
|
||||
|
@ -112,7 +112,7 @@ class StructElementNode {
|
|||
let kidDict = null;
|
||||
if (kid instanceof Ref) {
|
||||
kidDict = this.dict.xref.fetch(kid);
|
||||
} else if (isDict(kid)) {
|
||||
} else if (kid instanceof Dict) {
|
||||
kidDict = kid;
|
||||
}
|
||||
if (!kidDict) {
|
||||
|
@ -256,7 +256,7 @@ class StructTreePage {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (isDict(obj)) {
|
||||
if (obj instanceof Dict) {
|
||||
if (obj.objId !== dict.objId) {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue