1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:57:45 +00:00

LibJS: Change Intl's GetOption AO to accept a Span rather than a Vector

Allocating a Vector for each of these invocations is a bit silly when
the values are basically all compile-time arrays. This AO is used even
more heavily by Intl.DateTimeFormat, so change it to accept a Span to
reduce its cost.

This also adds an overload to accept a fixed-size C-array so callers do
not have to be prefixed with AK::Array, i.e. this:

    get_option(..., AK::Array { "a"sv, "b"sv }, ...);

Reduces to:

    get_option(..., { "a"sv, "b"sv }, ...);

(Which is how all call sites were already written to construct a Vector
in place).
This commit is contained in:
Timothy Flynn 2021-11-27 10:12:58 -05:00 committed by Linus Groh
parent 55aecf5381
commit bb11437792
3 changed files with 12 additions and 5 deletions

View file

@ -597,7 +597,7 @@ ThrowCompletionOr<Object*> coerce_options_to_object(GlobalObject& global_object,
}
// 9.2.13 GetOption ( options, property, type, values, fallback ), https://tc39.es/ecma402/#sec-getoption
ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, Value::Type type, Vector<StringView> const& values, Fallback fallback)
ThrowCompletionOr<Value> get_option(GlobalObject& global_object, Object const& options, PropertyKey const& property, Value::Type type, Span<StringView const> values, Fallback fallback)
{
auto& vm = global_object.vm();