Skip to content

Truly independent web browser

LibWeb: Ask less per element when publishing its features

Andreas Kling874f491af9b0
diff --git a/Libraries/LibWeb/CSS/PseudoClassBitmap.h b/Libraries/LibWeb/CSS/PseudoClassBitmap.h
index 53510d4b921..aba8128e446 100644
--- a/Libraries/LibWeb/CSS/PseudoClassBitmap.h
+++ b/Libraries/LibWeb/CSS/PseudoClassBitmap.h
@@ -7,6 +7,7 @@
#pragma once
#include <AK/Array.h>
+#include <AK/BuiltinWrappers.h>
#include <LibWeb/CSS/PseudoClass.h>
namespace Web::CSS {
@@ -38,6 +39,15 @@ public:
return (m_bits[word_index] & (1LLU << bit_index)) != 0;
}
+ template<typename Callback>
+ void for_each_set(Callback callback) const
+ {
+ for (size_t word_index = 0; word_index < word_count; ++word_index) {
+ for (u64 word = m_bits[word_index]; word != 0; word &= word - 1)
+ callback(static_cast<PseudoClass>(word_index * bits_per_word + count_trailing_zeroes(word)));
+ }
+ }
+
void operator|=(PseudoClassBitmap const& other)
{
for (size_t i = 0; i < word_count; ++i)
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
index d4c31d0cfad..317e7569179 100644
--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp
+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
@@ -1145,12 +1145,7 @@ static bool element_has_presentational_hints_to_publish(DOM::Element const& elem
&& (navigable->container()->has_attribute(HTML::AttributeNames::marginwidth) || navigable->container()->has_attribute(HTML::AttributeNames::marginheight)))
return true;
}
- bool has_presentational_hint = false;
- element.for_each_attribute([&](Utf16FlyString const& name, Utf16View) {
- if (!has_presentational_hint && element.is_presentational_hint(name))
- has_presentational_hint = true;
- });
- return has_presentational_hint;
+ return any_of(element.attribute_list(), [&](auto const& attribute) { return element.is_presentational_hint(attribute.name.as_string()); });
}
// The element facts the style computation's box-type transformation and element style adjustments