Skip to content

Commit 4f7303b

Browse files
committed
assert: use a set instead of an array for faster lookup
This is a very small improvement for error creation.
1 parent 9280e4f commit 4f7303b

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/internal/assert/assertion_error.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const {
1010
ObjectDefineProperty,
1111
ObjectGetPrototypeOf,
1212
ObjectPrototypeHasOwnProperty,
13+
SafeSet,
1314
String,
1415
StringPrototypeRepeat,
1516
StringPrototypeSlice,
@@ -42,7 +43,7 @@ const kReadableOperator = {
4243
const kMaxShortStringLength = 12;
4344
const kMaxLongStringLength = 512;
4445

45-
const kMethodsWithCustomMessageDiff = ['deepStrictEqual', 'strictEqual', 'partialDeepStrictEqual'];
46+
const kMethodsWithCustomMessageDiff = new SafeSet(['deepStrictEqual', 'strictEqual', 'partialDeepStrictEqual']);
4647

4748
function copyError(source) {
4849
const target = ObjectAssign(
@@ -263,7 +264,7 @@ class AssertionError extends Error {
263264
if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0;
264265

265266
if (message != null) {
266-
if (kMethodsWithCustomMessageDiff.includes(operator)) {
267+
if (kMethodsWithCustomMessageDiff.has(operator)) {
267268
super(createErrDiff(actual, expected, operator, message, diff));
268269
} else {
269270
super(String(message));
@@ -283,7 +284,7 @@ class AssertionError extends Error {
283284
expected = copyError(expected);
284285
}
285286

286-
if (kMethodsWithCustomMessageDiff.includes(operator)) {
287+
if (kMethodsWithCustomMessageDiff.has(operator)) {
287288
super(createErrDiff(actual, expected, operator, message, diff));
288289
} else if (operator === 'notDeepStrictEqual' ||
289290
operator === 'notStrictEqual') {

0 commit comments

Comments
 (0)