Skip to content

Commit 5517c94

Browse files
Merge pull request #10938 from Snuffleupagus/fewer-XRef-isCmd
Reduce the number of `isCmd` calls slightly in the `XRef` class
2 parents 2800962 + 41745a5 commit 5517c94

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/core/obj.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
warn
2121
} from '../shared/util';
2222
import {
23-
clearPrimitiveCaches, Dict, isCmd, isDict, isName, isRef, isRefsEqual,
23+
clearPrimitiveCaches, Cmd, Dict, isCmd, isDict, isName, isRef, isRefsEqual,
2424
isStream, Ref, RefSet, RefSetCache
2525
} from './primitives';
2626
import { Lexer, Parser } from './parser';
@@ -1200,10 +1200,15 @@ var XRef = (function XRefClosure() {
12001200
entry.gen = parser.getObj();
12011201
var type = parser.getObj();
12021202

1203-
if (isCmd(type, 'f')) {
1204-
entry.free = true;
1205-
} else if (isCmd(type, 'n')) {
1206-
entry.uncompressed = true;
1203+
if (type instanceof Cmd) {
1204+
switch (type.cmd) {
1205+
case 'f':
1206+
entry.free = true;
1207+
break;
1208+
case 'n':
1209+
entry.uncompressed = true;
1210+
break;
1211+
}
12071212
}
12081213

12091214
// Validate entry obj
@@ -1685,7 +1690,7 @@ var XRef = (function XRefClosure() {
16851690
if (!Number.isInteger(obj2)) {
16861691
obj2 = parseInt(obj2, 10);
16871692
}
1688-
if (obj1 !== num || obj2 !== gen || !isCmd(obj3)) {
1693+
if (obj1 !== num || obj2 !== gen || !(obj3 instanceof Cmd)) {
16891694
throw new XRefEntryException(`Bad (uncompressed) XRef entry: ${ref}`);
16901695
}
16911696
if (obj3.cmd !== 'obj') {

0 commit comments

Comments
 (0)