Skip to content

Commit

Permalink
[perf] replace Math.max usage to reduce and pure compare
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart committed Dec 5, 2023
1 parent 7b9b0cf commit e099bd9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/@glimmer/validator/lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,19 @@ class MonomorphicTagImpl<T extends MonomorphicTagId = MonomorphicTagId> {

if (subtag !== null) {
if (Array.isArray(subtag)) {
for (const tag of subtag) {
let value = tag[COMPUTE]();
revision = Math.max(value, revision);
}
revision = subtag.reduce((prev, currentTag: Tag) => {
let current = currentTag[COMPUTE]();
return current > prev ? current : prev;
}, revision);
} else {
let subtagValue = subtag[COMPUTE]();

if (subtagValue === this.subtagBufferCache) {
revision = Math.max(revision, this.lastValue);
revision = revision > this.lastValue ? revision : this.lastValue;
} else {
// Clear the temporary buffer cache
this.subtagBufferCache = null;
revision = Math.max(revision, subtagValue);
revision = revision > subtagValue ? revision : subtagValue;
}
}
}
Expand Down

0 comments on commit e099bd9

Please sign in to comment.