mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:07:36 +00:00
LibJS: Replace String const& with StringView in various Temporal AOs
This is especially helpful where we already pass StringView literals and only compare them with others, e.g. overflow and largest/smallest unit, in which case there's no need to actually allocate a string.
This commit is contained in:
parent
9c3da7a3e3
commit
81aaa9ccd5
11 changed files with 23 additions and 23 deletions
|
@ -319,7 +319,7 @@ Optional<SecondsStringPrecision> to_seconds_string_precision(GlobalObject& globa
|
|||
// 2. If smallestUnit is "minute", then
|
||||
if (smallest_unit == "minute"sv) {
|
||||
// a. Return the Record { [[Precision]]: "minute", [[Unit]]: "minute", [[Increment]]: 1 }.
|
||||
return SecondsStringPrecision { .precision = String { "minute"sv }, .unit = "minute"sv, .increment = 1 };
|
||||
return SecondsStringPrecision { .precision = "minute"sv, .unit = "minute"sv, .increment = 1 };
|
||||
}
|
||||
|
||||
// 3. If smallestUnit is "second", then
|
||||
|
@ -358,7 +358,7 @@ Optional<SecondsStringPrecision> to_seconds_string_precision(GlobalObject& globa
|
|||
if (digits_variant->has<String>()) {
|
||||
VERIFY(digits_variant->get<String>() == "auto"sv);
|
||||
// a. Return the Record { [[Precision]]: "auto", [[Unit]]: "nanosecond", [[Increment]]: 1 }.
|
||||
return SecondsStringPrecision { .precision = String { "auto"sv }, .unit = "nanosecond"sv, .increment = 1 };
|
||||
return SecondsStringPrecision { .precision = "auto"sv, .unit = "nanosecond"sv, .increment = 1 };
|
||||
}
|
||||
|
||||
auto digits = digits_variant->get<u8>();
|
||||
|
@ -478,7 +478,7 @@ Optional<String> to_smallest_temporal_unit(GlobalObject& global_object, Object&
|
|||
}
|
||||
|
||||
// 13.22 ValidateTemporalUnitRange ( largestUnit, smallestUnit ), https://tc39.es/proposal-temporal/#sec-temporal-validatetemporalunitrange
|
||||
void validate_temporal_unit_range(GlobalObject& global_object, String const& largest_unit, String const& smallest_unit)
|
||||
void validate_temporal_unit_range(GlobalObject& global_object, StringView largest_unit, StringView smallest_unit)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
@ -615,16 +615,16 @@ void reject_temporal_calendar_type(GlobalObject& global_object, Object& object)
|
|||
}
|
||||
|
||||
// 13.27 FormatSecondsStringPart ( second, millisecond, microsecond, nanosecond, precision ), https://tc39.es/proposal-temporal/#sec-temporal-formatsecondsstringpart
|
||||
String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<String, u8> const& precision)
|
||||
String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision)
|
||||
{
|
||||
// 1. Assert: second, millisecond, microsecond and nanosecond are integers.
|
||||
|
||||
// Non-standard sanity check
|
||||
if (precision.has<String>())
|
||||
VERIFY(precision.get<String>().is_one_of("minute"sv, "auto"sv));
|
||||
if (precision.has<StringView>())
|
||||
VERIFY(precision.get<StringView>().is_one_of("minute"sv, "auto"sv));
|
||||
|
||||
// 2. If precision is "minute", return "".
|
||||
if (precision.has<String>() && precision.get<String>() == "minute"sv)
|
||||
if (precision.has<StringView>() && precision.get<StringView>() == "minute"sv)
|
||||
return String::empty();
|
||||
|
||||
// 3. Let secondsString be the string-concatenation of the code unit 0x003A (COLON) and second formatted as a two-digit decimal number, padded to the left with zeroes if necessary.
|
||||
|
@ -636,7 +636,7 @@ String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u
|
|||
String fraction_string;
|
||||
|
||||
// 5. If precision is "auto", then
|
||||
if (precision.has<String>() && precision.get<String>() == "auto"sv) {
|
||||
if (precision.has<StringView>() && precision.get<StringView>() == "auto"sv) {
|
||||
// a. If fraction is 0, return secondsString.
|
||||
if (fraction == 0)
|
||||
return seconds_string;
|
||||
|
|
|
@ -71,7 +71,7 @@ struct TemporalTimeZone {
|
|||
};
|
||||
|
||||
struct SecondsStringPrecision {
|
||||
Variant<String, u8> precision;
|
||||
Variant<StringView, u8> precision;
|
||||
String unit;
|
||||
u32 increment;
|
||||
};
|
||||
|
@ -88,11 +88,11 @@ u64 to_temporal_rounding_increment(GlobalObject&, Object& normalized_options, Op
|
|||
Optional<SecondsStringPrecision> to_seconds_string_precision(GlobalObject&, Object& normalized_options);
|
||||
Optional<String> to_largest_temporal_unit(GlobalObject&, Object& normalized_options, Vector<StringView> const& disallowed_units, String const& fallback, Optional<String> auto_value);
|
||||
Optional<String> to_smallest_temporal_unit(GlobalObject&, Object& normalized_options, Vector<StringView> const& disallowed_units, Optional<String> fallback);
|
||||
void validate_temporal_unit_range(GlobalObject&, String const& largest_unit, String const& smallest_unit);
|
||||
void validate_temporal_unit_range(GlobalObject&, StringView largest_unit, StringView smallest_unit);
|
||||
String larger_of_two_temporal_units(StringView, StringView);
|
||||
Optional<u16> maximum_temporal_duration_rounding_increment(StringView unit);
|
||||
void reject_temporal_calendar_type(GlobalObject&, Object&);
|
||||
String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<String, u8> const& precision);
|
||||
String format_seconds_string_part(u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Variant<StringView, u8> const& precision);
|
||||
double constrain_to_range(double x, double minimum, double maximum);
|
||||
BigInt* round_number_to_increment(GlobalObject&, BigInt const&, u64 increment, StringView rounding_mode);
|
||||
Optional<ISODateTime> parse_iso_date_time(GlobalObject&, String const& iso_string);
|
||||
|
|
|
@ -248,7 +248,7 @@ BigInt* round_temporal_instant(GlobalObject& global_object, BigInt const& nanose
|
|||
}
|
||||
|
||||
// 8.5.9 TemporalInstantToString ( instant, timeZone, precision ), https://tc39.es/proposal-temporal/#sec-temporal-temporalinstanttostring
|
||||
Optional<String> temporal_instant_to_string(GlobalObject& global_object, Instant& instant, Value time_zone, Variant<String, u8> const& precision)
|
||||
Optional<String> temporal_instant_to_string(GlobalObject& global_object, Instant& instant, Value time_zone, Variant<StringView, u8> const& precision)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
|
|
@ -43,6 +43,6 @@ i32 compare_epoch_nanoseconds(BigInt const&, BigInt const&);
|
|||
BigInt* add_instant(GlobalObject&, BigInt const& epoch_nanoseconds, double hours, double minutes, double seconds, double milliseconds, double microseconds, double nanoseconds);
|
||||
BigInt* difference_instant(GlobalObject&, BigInt const& nanoseconds1, BigInt const& nanoseconds2, u64 rounding_increment, StringView smallest_unit, StringView rounding_mode);
|
||||
BigInt* round_temporal_instant(GlobalObject&, BigInt const& nanoseconds, u64 increment, StringView unit, StringView rounding_mode);
|
||||
Optional<String> temporal_instant_to_string(GlobalObject&, Instant&, Value time_zone, Variant<String, u8> const& precision);
|
||||
Optional<String> temporal_instant_to_string(GlobalObject&, Instant&, Value time_zone, Variant<StringView, u8> const& precision);
|
||||
|
||||
}
|
||||
|
|
|
@ -477,7 +477,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_locale_string)
|
|||
return {};
|
||||
|
||||
// 3. Return ? TemporalInstantToString(instant, undefined, "auto").
|
||||
auto string = temporal_instant_to_string(global_object, *instant, js_undefined(), String { "auto"sv });
|
||||
auto string = temporal_instant_to_string(global_object, *instant, js_undefined(), "auto"sv);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
|
@ -494,7 +494,7 @@ JS_DEFINE_NATIVE_FUNCTION(InstantPrototype::to_json)
|
|||
return {};
|
||||
|
||||
// 3. Return ? TemporalInstantToString(instant, undefined, "auto").
|
||||
auto string = temporal_instant_to_string(global_object, *instant, js_undefined(), String { "auto"sv });
|
||||
auto string = temporal_instant_to_string(global_object, *instant, js_undefined(), "auto"sv);
|
||||
if (vm.exception())
|
||||
return {};
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ PlainDate* to_temporal_date(GlobalObject& global_object, Value item, Object* opt
|
|||
}
|
||||
|
||||
// 3.5.4 RegulateISODate ( year, month, day, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisodate
|
||||
Optional<ISODate> regulate_iso_date(GlobalObject& global_object, double year, double month, double day, String const& overflow)
|
||||
Optional<ISODate> regulate_iso_date(GlobalObject& global_object, double year, double month, double day, StringView overflow)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
// 1. Assert: year, month, and day are integers.
|
||||
|
@ -380,7 +380,7 @@ Optional<String> temporal_date_to_string(GlobalObject& global_object, PlainDate&
|
|||
}
|
||||
|
||||
// 3.5.9 AddISODate ( year, month, day, years, months, weeks, days, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-addisodate
|
||||
Optional<ISODate> add_iso_date(GlobalObject& global_object, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, String const& overflow)
|
||||
Optional<ISODate> add_iso_date(GlobalObject& global_object, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
|
|
@ -42,12 +42,12 @@ struct ISODate {
|
|||
|
||||
PlainDate* create_temporal_date(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, Object& calendar, FunctionObject* new_target = nullptr);
|
||||
PlainDate* to_temporal_date(GlobalObject&, Value item, Object* options = nullptr);
|
||||
Optional<ISODate> regulate_iso_date(GlobalObject&, double year, double month, double day, String const& overflow);
|
||||
Optional<ISODate> regulate_iso_date(GlobalObject&, double year, double month, double day, StringView overflow);
|
||||
bool is_valid_iso_date(i32 year, u8 month, u8 day);
|
||||
ISODate balance_iso_date(double year, double month, double day);
|
||||
String pad_iso_year(i32 y);
|
||||
Optional<String> temporal_date_to_string(GlobalObject&, PlainDate&, StringView show_calendar);
|
||||
Optional<ISODate> add_iso_date(GlobalObject&, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, String const& overflow);
|
||||
Optional<ISODate> add_iso_date(GlobalObject&, i32 year, u8 month, u8 day, double years, double months, double weeks, double days, StringView overflow);
|
||||
i8 compare_iso_date(i32 year1, u8 month1, u8 day1, i32 year2, u8 month2, u8 day2);
|
||||
|
||||
}
|
||||
|
|
|
@ -303,7 +303,7 @@ PlainDateTime* create_temporal_date_time(GlobalObject& global_object, i32 iso_ye
|
|||
}
|
||||
|
||||
// 5.5.7 TemporalDateTimeToString ( isoYear, isoMonth, isoDay, hour, minute, second, millisecond, microsecond, nanosecond, calendar, precision, showCalendar ), , https://tc39.es/proposal-temporal/#sec-temporal-temporaldatetimetostring
|
||||
Optional<String> temporal_date_time_to_string(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<String, u8> const& precision, StringView show_calendar)
|
||||
Optional<String> temporal_date_time_to_string(GlobalObject& global_object, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ Optional<ISODateTime> interpret_temporal_date_time_fields(GlobalObject&, Object&
|
|||
PlainDateTime* to_temporal_date_time(GlobalObject&, Value item, Object* options = nullptr);
|
||||
ISODateTime balance_iso_date_time(i32 year, u8 month, u8 day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, i64 nanosecond);
|
||||
PlainDateTime* create_temporal_date_time(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Object& calendar, FunctionObject* new_target = nullptr);
|
||||
Optional<String> temporal_date_time_to_string(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<String, u8> const& precision, StringView show_calendar);
|
||||
Optional<String> temporal_date_time_to_string(GlobalObject&, i32 iso_year, u8 iso_month, u8 iso_day, u8 hour, u8 minute, u8 second, u16 millisecond, u16 microsecond, u16 nanosecond, Value calendar, Variant<StringView, u8> const& precision, StringView show_calendar);
|
||||
i8 compare_iso_date_time(i32 year1, u8 month1, u8 day1, u8 hour1, u8 minute1, u8 second1, u16 millisecond1, u16 microsecond1, u16 nanosecond1, i32 year2, u8 month2, u8 day2, u8 hour2, u8 minute2, u8 second2, u16 millisecond2, u16 microsecond2, u16 nanosecond2);
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void PlainYearMonth::visit_edges(Visitor& visitor)
|
|||
}
|
||||
|
||||
// 9.5.2 RegulateISOYearMonth ( year, month, overflow ), https://tc39.es/proposal-temporal/#sec-temporal-regulateisoyearmonth
|
||||
Optional<ISOYearMonth> regulate_iso_year_month(GlobalObject& global_object, double year, double month, String const& overflow)
|
||||
Optional<ISOYearMonth> regulate_iso_year_month(GlobalObject& global_object, double year, double month, StringView overflow)
|
||||
{
|
||||
auto& vm = global_object.vm();
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ struct ISOYearMonth {
|
|||
u8 reference_iso_day;
|
||||
};
|
||||
|
||||
Optional<ISOYearMonth> regulate_iso_year_month(GlobalObject&, double year, double month, String const& overflow);
|
||||
Optional<ISOYearMonth> regulate_iso_year_month(GlobalObject&, double year, double month, StringView overflow);
|
||||
bool is_valid_iso_month(u8 month);
|
||||
bool iso_year_month_within_limits(i32 year, u8 month);
|
||||
ISOYearMonth balance_iso_year_month(double year, double month);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue