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

LibWeb: Use Vector::in_reverse() in HTML::StackOfOpenElements

This commit is contained in:
Andreas Kling 2022-04-13 19:21:43 +02:00
parent 83082b12b7
commit b0008c0934

View file

@ -16,11 +16,10 @@ StackOfOpenElements::~StackOfOpenElements() = default;
bool StackOfOpenElements::has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const& list) const bool StackOfOpenElements::has_in_scope_impl(FlyString const& tag_name, Vector<FlyString> const& list) const
{ {
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) { for (auto const& element : m_elements.in_reverse()) {
auto& node = m_elements.at(i); if (element.local_name() == tag_name)
if (node.local_name() == tag_name)
return true; return true;
if (list.contains_slow(node.local_name())) if (list.contains_slow(element.local_name()))
return false; return false;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
@ -33,11 +32,10 @@ bool StackOfOpenElements::has_in_scope(FlyString const& tag_name) const
bool StackOfOpenElements::has_in_scope_impl(const DOM::Element& target_node, Vector<FlyString> const& list) const bool StackOfOpenElements::has_in_scope_impl(const DOM::Element& target_node, Vector<FlyString> const& list) const
{ {
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) { for (auto& element : m_elements.in_reverse()) {
auto& node = m_elements.at(i); if (&element == &target_node)
if (&node == &target_node)
return true; return true;
if (list.contains_slow(node.local_name())) if (list.contains_slow(element.local_name()))
return false; return false;
} }
VERIFY_NOT_REACHED(); VERIFY_NOT_REACHED();
@ -77,9 +75,8 @@ bool StackOfOpenElements::has_in_list_item_scope(FlyString const& tag_name) cons
bool StackOfOpenElements::has_in_select_scope(FlyString const& tag_name) const bool StackOfOpenElements::has_in_select_scope(FlyString const& tag_name) const
{ {
// https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-the-specific-scope // https://html.spec.whatwg.org/multipage/parsing.html#has-an-element-in-the-specific-scope
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) { // 1. Initialize node to be the current node (the bottommost node of the stack).
// 1. Initialize node to be the current node (the bottommost node of the stack). for (auto& node : m_elements.in_reverse()) {
auto& node = m_elements.at(i);
// 2. If node is the target node, terminate in a match state. // 2. If node is the target node, terminate in a match state.
if (node.local_name() == tag_name) if (node.local_name() == tag_name)
return true; return true;
@ -122,8 +119,7 @@ void StackOfOpenElements::pop_until_an_element_with_tag_name_has_been_popped(Fly
DOM::Element* StackOfOpenElements::topmost_special_node_below(const DOM::Element& formatting_element) DOM::Element* StackOfOpenElements::topmost_special_node_below(const DOM::Element& formatting_element)
{ {
DOM::Element* found_element = nullptr; DOM::Element* found_element = nullptr;
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) { for (auto& element : m_elements.in_reverse()) {
auto& element = m_elements[i];
if (&element == &formatting_element) if (&element == &formatting_element)
break; break;
if (HTMLParser::is_special_tag(element.local_name(), element.namespace_())) if (HTMLParser::is_special_tag(element.local_name(), element.namespace_()))
@ -145,8 +141,7 @@ StackOfOpenElements::LastElementResult StackOfOpenElements::last_element_with_ta
DOM::Element* StackOfOpenElements::element_immediately_above(DOM::Element const& target) DOM::Element* StackOfOpenElements::element_immediately_above(DOM::Element const& target)
{ {
bool found_target = false; bool found_target = false;
for (ssize_t i = m_elements.size() - 1; i >= 0; --i) { for (auto& element : m_elements.in_reverse()) {
auto& element = m_elements[i];
if (&element == &target) { if (&element == &target) {
found_target = true; found_target = true;
} else if (found_target) } else if (found_target)