Skip to content

Commit

Permalink
Remove the isBool helper function
Browse files Browse the repository at this point in the history
The call-sites are replaced by direct `typeof`-checks instead, which removes unnecessary function calls. Note that in the `src/`-folder we already had more `typeof`-cases than `isBool`-calls.
  • Loading branch information
Snuffleupagus committed Feb 23, 2022
1 parent 82f1ee1 commit fcfda60
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
5 changes: 2 additions & 3 deletions src/core/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
DocumentActionEventType,
FormatError,
info,
isBool,
isString,
objectSize,
PermissionFlag,
Expand Down Expand Up @@ -221,7 +220,7 @@ class Catalog {
continue;
}
const value = obj.get(key);
if (!isBool(value)) {
if (typeof value !== "boolean") {
continue;
}
markInfo[key] = value;
Expand Down Expand Up @@ -1521,7 +1520,7 @@ class Catalog {
}
// The 'NewWindow' property, equal to `LinkTarget.BLANK`.
const newWindow = action.get("NewWindow");
if (isBool(newWindow)) {
if (typeof newWindow === "boolean") {
resultObj.newWindow = newWindow;
}
break;
Expand Down
9 changes: 4 additions & 5 deletions src/core/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Dict, Ref } from "./primitives.js";
import {
FormatError,
info,
isBool,
IsEvalSupportedCached,
shadow,
unreachable,
Expand Down Expand Up @@ -627,7 +626,7 @@ class PostScriptEvaluator {
case "and":
b = stack.pop();
a = stack.pop();
if (isBool(a) && isBool(b)) {
if (typeof a === "boolean" && typeof b === "boolean") {
stack.push(a && b);
} else {
stack.push(a & b);
Expand Down Expand Up @@ -751,7 +750,7 @@ class PostScriptEvaluator {
break;
case "not":
a = stack.pop();
if (isBool(a)) {
if (typeof a === "boolean") {
stack.push(!a);
} else {
stack.push(~a);
Expand All @@ -760,7 +759,7 @@ class PostScriptEvaluator {
case "or":
b = stack.pop();
a = stack.pop();
if (isBool(a) && isBool(b)) {
if (typeof a === "boolean" && typeof b === "boolean") {
stack.push(a || b);
} else {
stack.push(a | b);
Expand Down Expand Up @@ -802,7 +801,7 @@ class PostScriptEvaluator {
case "xor":
b = stack.pop();
a = stack.pop();
if (isBool(a) && isBool(b)) {
if (typeof a === "boolean" && typeof b === "boolean") {
stack.push(a !== b);
} else {
stack.push(a ^ b);
Expand Down
5 changes: 0 additions & 5 deletions src/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1030,10 +1030,6 @@ function utf8StringToString(str) {
return unescape(encodeURIComponent(str));
}

function isBool(v) {
return typeof v === "boolean";
}

function isString(v) {
return typeof v === "string";
}
Expand Down Expand Up @@ -1139,7 +1135,6 @@ export {
isArrayBuffer,
isArrayEqual,
isAscii,
isBool,
IsEvalSupportedCached,
IsLittleEndianCached,
isSameOrigin,
Expand Down
17 changes: 0 additions & 17 deletions test/unit/util_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
getModificationDate,
isArrayBuffer,
isAscii,
isBool,
isSameOrigin,
isString,
string32,
Expand Down Expand Up @@ -74,22 +73,6 @@ describe("util", function () {
});
});

describe("isBool", function () {
it("handles boolean values", function () {
expect(isBool(true)).toEqual(true);
expect(isBool(false)).toEqual(true);
});

it("handles non-boolean values", function () {
expect(isBool("true")).toEqual(false);
expect(isBool("false")).toEqual(false);
expect(isBool(1)).toEqual(false);
expect(isBool(0)).toEqual(false);
expect(isBool(null)).toEqual(false);
expect(isBool(undefined)).toEqual(false);
});
});

describe("isString", function () {
it("handles string values", function () {
expect(isString("foo")).toEqual(true);
Expand Down

0 comments on commit fcfda60

Please sign in to comment.