Skip to content

Truly independent web browser

LibWeb: Return the values of a CSSNumericArray as a span

Shannon Booth3db5e5db78fa
diff --git a/Libraries/LibWeb/CSS/CSSNumericArray.h b/Libraries/LibWeb/CSS/CSSNumericArray.h
index c8d162ed33c..fa0364c84f6 100644
--- a/Libraries/LibWeb/CSS/CSSNumericArray.h
+++ b/Libraries/LibWeb/CSS/CSSNumericArray.h
@@ -24,7 +24,7 @@ public:
WebIDL::UnsignedLong length() const;
GC::Ptr<CSSNumericValue> value_at(size_t index) const;
- Vector<GC::Ref<CSSNumericValue>> values() { return m_values; }
+ ReadonlySpan<GC::Ref<CSSNumericValue>> values() const { return m_values; }
virtual void visit_edges(GC::Cell::Visitor&) override;
bool is_equal_numeric_values(GC::Ref<CSSNumericArray> other) const;
diff --git a/Libraries/LibWeb/CSS/CSSNumericValue.cpp b/Libraries/LibWeb/CSS/CSSNumericValue.cpp
index b21645dd944..e7766e40843 100644
--- a/Libraries/LibWeb/CSS/CSSNumericValue.cpp
+++ b/Libraries/LibWeb/CSS/CSSNumericValue.cpp
@@ -125,10 +125,12 @@ WebIDL::ExceptionOr<GC::Ref<CSSNumericValue>> CSSNumericValue::add(ReadonlySpan<
// NB: We reorder the steps a little to avoid the awkward prepending.
GC::RootVector<GC::Ref<CSSNumericValue>> values;
- if (auto const* math_sum = as_if<CSSMathSum>(*this))
- values.extend(math_sum->values()->values());
- else
+ if (auto const* math_sum = as_if<CSSMathSum>(*this)) {
+ auto items = math_sum->values()->values();
+ values.append(items.data(), items.size());
+ } else {
values.append(*this);
+ }
for (auto const& value : initial_values)
values.append(rectify_a_numberish_value(value));
@@ -183,10 +185,12 @@ WebIDL::ExceptionOr<GC::Ref<CSSNumericValue>> CSSNumericValue::mul(ReadonlySpan<
// NB: We reorder the steps a little to avoid the awkward prepending.
GC::RootVector<GC::Ref<CSSNumericValue>> values;
- if (auto const* math_product = as_if<CSSMathProduct>(*this))
- values.extend(math_product->values()->values());
- else
+ if (auto const* math_product = as_if<CSSMathProduct>(*this)) {
+ auto items = math_product->values()->values();
+ values.append(items.data(), items.size());
+ } else {
values.append(*this);
+ }
for (auto const& value : initial_values)
values.append(rectify_a_numberish_value(value));
@@ -277,10 +281,12 @@ WebIDL::ExceptionOr<GC::Ref<CSSNumericValue>> CSSNumericValue::min(ReadonlySpan<
// NB: We reorder the steps a little to avoid the awkward prepending.
GC::RootVector<GC::Ref<CSSNumericValue>> values;
- if (auto const* math_product = as_if<CSSMathMin>(*this))
- values.extend(math_product->values()->values());
- else
+ if (auto const* math_product = as_if<CSSMathMin>(*this)) {
+ auto items = math_product->values()->values();
+ values.append(items.data(), items.size());
+ } else {
values.append(*this);
+ }
for (auto const& value : initial_values)
values.append(rectify_a_numberish_value(value));
@@ -305,10 +311,12 @@ WebIDL::ExceptionOr<GC::Ref<CSSNumericValue>> CSSNumericValue::max(ReadonlySpan<
// NB: We reorder the steps a little to avoid the awkward prepending.
GC::RootVector<GC::Ref<CSSNumericValue>> values;
- if (auto const* math_product = as_if<CSSMathMax>(*this))
- values.extend(math_product->values()->values());
- else
+ if (auto const* math_product = as_if<CSSMathMax>(*this)) {
+ auto items = math_product->values()->values();
+ values.append(items.data(), items.size());
+ } else {
values.append(*this);
+ }
for (auto const& value : initial_values)
values.append(rectify_a_numberish_value(value));