From d78a007b5d8495a6ff465a72cb11698926d155e6 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 14 Jul 2021 13:31:49 +0200 Subject: [PATCH] LibWeb: Use split_view() in attribute selector matching Using split() creates a new String object for each of the split tokens. Use split_view() instead to avoid these unnecessary heap allocations. --- Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp index de5dd52b67..8a93889db4 100644 --- a/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp +++ b/Userland/Libraries/LibWeb/CSS/SelectorEngine.cpp @@ -35,13 +35,13 @@ static bool matches_attribute(CSS::Selector::SimpleSelector::Attribute const& at return element.attribute(attribute.name) == attribute.value; break; case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsWord: - return element.attribute(attribute.name).split(' ').contains_slow(attribute.value); + return element.attribute(attribute.name).split_view(' ').contains_slow(attribute.value); break; case CSS::Selector::SimpleSelector::Attribute::MatchType::ContainsString: return element.attribute(attribute.name).contains(attribute.value); break; case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithSegment: - return element.attribute(attribute.name).split('-').first() == attribute.value; + return element.attribute(attribute.name).split_view('-').first() == attribute.value; break; case CSS::Selector::SimpleSelector::Attribute::MatchType::StartsWithString: return element.attribute(attribute.name).starts_with(attribute.value);