Skip to content

Commit

Permalink
Slightly re-factor the String handling in StatTimer
Browse files Browse the repository at this point in the history
This uses template strings in a couple of spots, and a buffer in the `toString` method.
  • Loading branch information
Snuffleupagus committed Oct 23, 2019
1 parent 60165a8 commit efa6f53
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,14 @@ class StatTimer {

time(name) {
if (name in this.started) {
warn('Timer is already running for ' + name);
warn(`Timer is already running for ${name}`);
}
this.started[name] = Date.now();
}

timeEnd(name) {
if (!(name in this.started)) {
warn('Timer has not been started for ' + name);
warn(`Timer has not been started for ${name}`);
}
this.times.push({
'name': name,
Expand All @@ -407,7 +407,7 @@ class StatTimer {

toString() {
// Find the longest name for padding purposes.
let out = '', longest = 0;
let outBuf = [], longest = 0;
for (const time of this.times) {
const name = time.name;
if (name.length > longest) {
Expand All @@ -416,9 +416,9 @@ class StatTimer {
}
for (const time of this.times) {
const duration = time.end - time.start;
out += `${time.name.padEnd(longest)} ${duration}ms\n`;
outBuf.push(`${time.name.padEnd(longest)} ${duration}ms\n`);
}
return out;
return outBuf.join('');
}
}

Expand Down

0 comments on commit efa6f53

Please sign in to comment.