Skip to content

Commit

Permalink
WIP: Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
ptomato committed May 1, 2024
1 parent 4c0db16 commit 2845e80
Show file tree
Hide file tree
Showing 3 changed files with 650 additions and 634 deletions.
13 changes: 6 additions & 7 deletions polyfill/lib/duration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import { TimeDuration } from './timeduration.mjs';

const MathAbs = Math.abs;
const NumberIsNaN = Number.isNaN;
const ObjectCreate = Object.create;

export class Duration {
Expand Down Expand Up @@ -345,9 +346,7 @@ export class Duration {
ES.DifferenceZonedDateTimeWithRounding(
relativeEpochNs,
targetEpochNs,
plainRelativeTo,
calendarRec,
zonedRelativeTo,
timeZoneRec,
precalculatedPlainDateTime,
ObjectCreate(null),
Expand Down Expand Up @@ -399,7 +398,7 @@ export class Duration {
if (ES.IsCalendarUnit(smallestUnit)) {
throw new RangeError(`a starting point is required for ${smallestUnit}s rounding`);
}
({ days, norm } = ES.RoundDuration(0, 0, 0, days, norm, roundingIncrement, smallestUnit, roundingMode));
({ days, norm } = ES.RoundDuration(days, norm, roundingIncrement, smallestUnit, roundingMode));
({ days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.BalanceTimeDuration(
norm.add24HourDays(days),
largestUnit
Expand Down Expand Up @@ -468,9 +467,7 @@ export class Duration {
const { total } = ES.DifferenceZonedDateTimeWithRounding(
relativeEpochNs,
targetEpochNs,
plainRelativeTo,
calendarRec,
zonedRelativeTo,
timeZoneRec,
precalculatedPlainDateTime,
ObjectCreate(null),
Expand All @@ -479,6 +476,7 @@ export class Duration {
unit,
'trunc'
);
if (NumberIsNaN(total)) throw new Error('assertion failed: total hit unexpected code path');
return total;
}

Expand Down Expand Up @@ -513,6 +511,7 @@ export class Duration {
unit,
'trunc'
);
if (NumberIsNaN(total)) throw new Error('assertion failed: total hit unexpected code path');
return total;
}

Expand All @@ -524,7 +523,7 @@ export class Duration {
throw new RangeError(`a starting point is required for ${unit}s total`);
}
norm = norm.add24HourDays(days);
const { total } = ES.RoundDuration(0, 0, 0, 0, norm, 1, unit, 'trunc');
const { total } = ES.RoundDuration(0, norm, 1, unit, 'trunc');
return total;
}
toString(options = undefined) {
Expand Down Expand Up @@ -563,7 +562,7 @@ export class Duration {
microseconds,
nanoseconds
);
({ norm } = ES.RoundDuration(0, 0, 0, 0, norm, increment, unit, roundingMode));
({ norm } = ES.RoundDuration(0, norm, increment, unit, roundingMode));
let deltaDays;
({
days: deltaDays,
Expand Down
Loading

0 comments on commit 2845e80

Please sign in to comment.