Skip to content

Commit e1cc2cd

Browse files
committed
Short-circuit common case of comparing a calendar or time zone to itself
In CalendarEquals, TimeZoneEquals, and ConsolidateCalendars, remove the observable toString() calls from the path where both calendars are the same object. See: #1425
1 parent 43d33f0 commit e1cc2cd

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/ecmascript.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,11 +1869,13 @@ export const ES = ObjectAssign({}, ES2020, {
18691869
return cal1 < cal2 ? -1 : cal1 > cal2 ? 1 : 0;
18701870
},
18711871
CalendarEquals: (one, two) => {
1872+
if (one === two) return true;
18721873
const cal1 = ES.ToString(one);
18731874
const cal2 = ES.ToString(two);
18741875
return cal1 === cal2;
18751876
},
18761877
ConsolidateCalendars: (one, two) => {
1878+
if (one === two) return two;
18771879
const sOne = ES.ToString(one);
18781880
const sTwo = ES.ToString(two);
18791881
if (sOne === sTwo || sOne === 'iso8601') {
@@ -1918,6 +1920,7 @@ export const ES = ObjectAssign({}, ES2020, {
19181920
return new TemporalTimeZone(timeZone);
19191921
},
19201922
TimeZoneEquals: (one, two) => {
1923+
if (one === two) return true;
19211924
const tz1 = ES.ToString(one);
19221925
const tz2 = ES.ToString(two);
19231926
return tz1 === tz2;

0 commit comments

Comments
 (0)