Skip to content

Commit

Permalink
console: minor timeLogImpl() refactor
Browse files Browse the repository at this point in the history
This commit does two things:

- Reverses the boolean value returned by timeLogImpl(). The new
  values make more sense semantically (IMO anyway), and save a
  a single NOT operation.
- Explicitly check for undefined when calling _times.get()
  instead of coercing the value.

PR-URL: #29100
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
cjihrig authored and targos committed Aug 19, 2019
1 parent 31c50e5 commit b085b94
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/internal/console/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ const consoleMethods = {
timeEnd(label = 'default') {
// Coerces everything other than Symbol to a string
label = `${label}`;
const hasWarned = timeLogImpl(this, 'timeEnd', label);
const found = timeLogImpl(this, 'timeEnd', label);
trace(kTraceEnd, kTraceConsoleCategory, `time::${label}`, 0);
if (!hasWarned) {
if (found) {
this._times.delete(label);
}
},
Expand Down Expand Up @@ -509,12 +509,12 @@ const consoleMethods = {
},
};

// Returns true if label was not found
// Returns true if label was found
function timeLogImpl(self, name, label, data) {
const time = self._times.get(label);
if (!time) {
if (time === undefined) {
process.emitWarning(`No such label '${label}' for console.${name}()`);
return true;
return false;
}
const duration = process.hrtime(time);
const ms = duration[0] * 1000 + duration[1] / 1e6;
Expand All @@ -523,7 +523,7 @@ function timeLogImpl(self, name, label, data) {
} else {
self.log('%s: %sms', label, ms.toFixed(3), ...data);
}
return false;
return true;
}

const keyKey = 'Key';
Expand Down

0 comments on commit b085b94

Please sign in to comment.