From aca09cae0aafec394be0492bb78e0463ebb874e3 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 16 Apr 2021 14:36:21 -0700 Subject: [PATCH] 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 --- polyfill/lib/ecmascript.mjs | 3 +++ spec/calendar.html | 12 ++++++++++++ spec/timezone.html | 6 ++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index db9183ecbb..9010541866 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -1869,11 +1869,13 @@ export const ES = ObjectAssign({}, ES2020, { return cal1 < cal2 ? -1 : cal1 > cal2 ? 1 : 0; }, CalendarEquals: (one, two) => { + if (one === two) return true; const cal1 = ES.ToString(one); const cal2 = ES.ToString(two); return cal1 === cal2; }, ConsolidateCalendars: (one, two) => { + if (one === two) return two; const sOne = ES.ToString(one); const sTwo = ES.ToString(two); if (sOne === sTwo || sOne === 'iso8601') { @@ -1918,6 +1920,7 @@ export const ES = ObjectAssign({}, ES2020, { return new TemporalTimeZone(timeZone); }, TimeZoneEquals: (one, two) => { + if (one === two) return true; const tz1 = ES.ToString(one); const tz2 = ES.ToString(two); return tz1 === tz2; diff --git a/spec/calendar.html b/spec/calendar.html index 64334ab295..9f5a8c8a48 100644 --- a/spec/calendar.html +++ b/spec/calendar.html @@ -328,7 +328,13 @@

FormatCalendarAnnotation ( _id_, _showCalendar_ )

CalendarEquals ( _one_, _two_ )

+

+ The abstract operation CalendarEquals takes two arguments _one_ and _two_, which must be Objects. + It returns *true* if its arguments represent the same calendar. + It performs the following steps: +

+ 1. If _one_ and _two_ are the same Object value, return *true*. 1. Let _calendarOne_ be ? ToString(_one_). 1. Let _calendarTwo_ be ? ToString(_two_). 1. If _calendarOne_ is _calendarTwo_, return *true*. @@ -338,7 +344,13 @@

CalendarEquals ( _one_, _two_ )

ConsolidateCalendars ( _one_, _two_ )

+

+ The abstract operation ConsolidateCalendars takes two arguments _one_ and _two_, which must be Objects. + It returns the calendar that should take priority when combining two Temporal objects with different calendars, or throws an exception if the calendars cannot be combined. + It performs the following steps: +

+ 1. If _one_ and _two_ are the same Object value, return _two_. 1. Let _calendarOne_ be ? ToString(_one_). 1. Let _calendarTwo_ be ? ToString(_two_). 1. If _calendarOne_ is _calendarTwo_, return _two_. diff --git a/spec/timezone.html b/spec/timezone.html index d0d96ff562..00b14e5976 100644 --- a/spec/timezone.html +++ b/spec/timezone.html @@ -644,10 +644,12 @@

GetPossibleInstantsFor ( _timeZone_, _dateTime_ )

TimeZoneEquals ( _one_, _two_ )

- The abstract operation TimeZoneEquals returns *true* if the results of - calling `toString()` on its arguments are equal. + The abstract operation TimeZoneEquals takes two arguments _one_ and _two_, which must be Objects. + It returns *true* if its arguments represent the same time zone. + It performs the following steps:

+ 1. If _one_ and _two_ are the same Object value, return *true*. 1. Let _timeZoneOne_ be ? ToString(_one_). 1. Let _timeZoneTwo_ be ? ToString(_two_). 1. If _timeZoneOne_ is _timeZoneTwo_, return *true*.