瀏覽代碼

LibWeb: Add a Vector::ensure_capacity() in collect_matching_rules()

Avoid some incremental Vector growth by pre-allocating enough capacity
to cover the case where every single selector matches an element.
Andreas Kling 3 年之前
父節點
當前提交
c1e6fc67a1
共有 1 個文件被更改,包括 1 次插入0 次删除
  1. 1 0
      Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

+ 1 - 0
Userland/Libraries/LibWeb/CSS/StyleComputer.cpp

@@ -92,6 +92,7 @@ Vector<MatchingRule> StyleComputer::collect_matching_rules(DOM::Element const& e
         }
 
         Vector<MatchingRule> matching_rules;
+        matching_rules.ensure_capacity(rules_to_run.size());
         for (auto const& rule_to_run : rules_to_run) {
             auto const& selector = rule_to_run.rule->selectors()[rule_to_run.selector_index];
             if (SelectorEngine::matches(selector, element, pseudo_element))