Skip to content

Commit

Permalink
process: simplify check in previousValueIsValid()
Browse files Browse the repository at this point in the history
This commit replaces a call to Number.isFinite() with a
cheaper typeof check. The subsequent range checks ensure that
the checked value is finite.

PR-URL: nodejs#24836
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
  • Loading branch information
cjihrig authored and Trott committed Dec 7, 2018
1 parent df19b07 commit 4ebb3f3
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/process/per_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ function setupCpuUsage(_cpuUsage) {
// Ensure that a previously passed in value is valid. Currently, the native
// implementation always returns numbers <= Number.MAX_SAFE_INTEGER.
function previousValueIsValid(num) {
return Number.isFinite(num) &&
return typeof num === 'number' &&
num <= Number.MAX_SAFE_INTEGER &&
num >= 0;
}
Expand Down

0 comments on commit 4ebb3f3

Please sign in to comment.