LibWeb: Do not copy the result of HeaderList::extract_header_list_values

There's no need to copy the Vector out of this result every time we call
it. We can move it out or access it directly.
This commit is contained in:
Timothy Flynn 2025-11-25 11:09:28 -05:00 committed by Tim Flynn
parent 44fbf6451e
commit ed27eea091
Notes: github-actions[bot] 2025-11-26 14:16:24 +00:00
4 changed files with 45 additions and 39 deletions

View file

@ -126,15 +126,13 @@ ErrorOr<Optional<URL::URL>> Response::location_url(Optional<String> const& reque
// 2. Let location be the result of extracting header list values given `Location` and responses header list.
auto location_values_or_failure = m_header_list->extract_header_list_values("Location"sv.bytes());
if (location_values_or_failure.has<Infrastructure::HeaderList::ExtractHeaderParseFailure>() || location_values_or_failure.has<Empty>())
return Optional<URL::URL> {};
auto const* location_values = location_values_or_failure.get_pointer<Vector<ByteBuffer>>();
auto const& location_values = location_values_or_failure.get<Vector<ByteBuffer>>();
if (location_values.size() != 1)
return Optional<URL::URL> {};
if (!location_values || location_values->size() != 1)
return OptionalNone {};
// 3. If location is a header value, then set location to the result of parsing location with responses URL.
auto location = DOMURL::parse(location_values.first(), url());
auto location = DOMURL::parse(location_values->first(), url());
if (!location.has_value())
return Error::from_string_literal("Invalid 'Location' header URL");