assert: prefer reference comparison over string comparison
Pointer comparison takes constant time and string comparison takes linear time unless there is some string interning going on, so this might be a little bit faster. Signed-off-by: Darshan Sen <darshan.sen@postman.com> PR-URL: https://github.com/nodejs/node/pull/41015 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
This commit is contained in:
parent
0d9f3bd9e8
commit
ced5fc3930
@ -831,7 +831,7 @@ function expectsError(stackStartFn, actual, error, message) {
|
||||
details += ` (${error.name})`;
|
||||
}
|
||||
details += message ? `: ${message}` : '.';
|
||||
const fnType = stackStartFn.name === 'rejects' ? 'rejection' : 'exception';
|
||||
const fnType = stackStartFn === assert.rejects ? 'rejection' : 'exception';
|
||||
innerFail({
|
||||
actual: undefined,
|
||||
expected: error,
|
||||
@ -878,7 +878,7 @@ function expectsNoError(stackStartFn, actual, error, message) {
|
||||
|
||||
if (!error || hasMatchingError(actual, error)) {
|
||||
const details = message ? `: ${message}` : '.';
|
||||
const fnType = stackStartFn.name === 'doesNotReject' ?
|
||||
const fnType = stackStartFn === assert.doesNotReject ?
|
||||
'rejection' : 'exception';
|
||||
innerFail({
|
||||
actual,
|
||||
@ -998,7 +998,7 @@ function internalMatch(string, regexp, message, fn) {
|
||||
'regexp', 'RegExp', regexp
|
||||
);
|
||||
}
|
||||
const match = fn.name === 'match';
|
||||
const match = fn === assert.match;
|
||||
if (typeof string !== 'string' ||
|
||||
RegExpPrototypeTest(regexp, string) !== match) {
|
||||
if (message instanceof Error) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user