Changeset 234825 in webkit
- Timestamp:
- Aug 13, 2018, 4:36:09 PM (7 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r234818 r234825 1 2018-08-13 Alex Christensen <achristensen@webkit.org> 2 3 Make CSSSelectorList a little more sane 4 https://bugs.webkit.org/show_bug.cgi?id=188539 5 6 Reviewed by Simon Fraser. 7 8 This patch does four things: 9 1. Use a UniqueArray<CSSSelector> instead of a raw pointer and manually calling destructors. 10 2. Use move semantics a little bit better. 11 3. Add a CSSSelectorList&& to the StyleRule and StyleRulePage because every time we create either 12 one of those objects we call a setter to give it a CSSSelectorList. That's what constructor arguments are for. 13 4. Don't use CSSSelectorList.componentCount(), which iterates all components, to determine if it's empty. 14 Use first() instead. 15 16 * css/CSSPageRule.cpp: 17 (WebCore::CSSPageRule::setSelectorText): 18 * css/CSSSelectorList.cpp: 19 (WebCore::CSSSelectorList::CSSSelectorList): 20 (WebCore::CSSSelectorList::componentCount const): 21 (WebCore::CSSSelectorList::listSize const): 22 (WebCore::CSSSelectorList::operator=): 23 (WebCore::CSSSelectorList::deleteSelectors): Deleted. 24 * css/CSSSelectorList.h: 25 (WebCore::CSSSelectorList::CSSSelectorList): 26 (WebCore::CSSSelectorList::first const): 27 (WebCore::CSSSelectorList::indexOfNextSelectorAfter const): 28 (WebCore::CSSSelectorList::~CSSSelectorList): Deleted. 29 (WebCore::CSSSelectorList::adoptSelectorArray): Deleted. 30 (WebCore::CSSSelectorList::hasOneSelector const): Deleted. 31 * css/CSSStyleRule.cpp: 32 (WebCore::CSSStyleRule::setSelectorText): 33 * css/StyleRule.cpp: 34 (WebCore::StyleRule::StyleRule): 35 (WebCore::StyleRule::createForSplitting): 36 (WebCore::StyleRulePage::StyleRulePage): 37 * css/StyleRule.h: 38 * css/parser/CSSParserImpl.cpp: 39 (WebCore::CSSParserImpl::consumePageRule): 40 (WebCore::CSSParserImpl::consumeStyleRule): 41 * css/parser/CSSSelectorParser.cpp: 42 (WebCore::CSSSelectorParser::consumePseudo): 43 1 44 2018-08-13 Ali Juma <ajuma@chromium.org> 2 45 -
trunk/Source/WebCore/css/CSSPageRule.cpp
r219237 r234825 78 78 CSSStyleSheet::RuleMutationScope mutationScope(this); 79 79 80 m_pageRule->wrapperAdoptSelectorList( selectorList);80 m_pageRule->wrapperAdoptSelectorList(WTFMove(selectorList)); 81 81 } 82 82 -
trunk/Source/WebCore/css/CSSSelectorList.cpp
r234814 r234825 38 38 ASSERT_WITH_SECURITY_IMPLICATION(otherComponentCount); 39 39 40 m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * otherComponentCount));40 m_selectorArray = makeUniqueArray<CSSSelector>(otherComponentCount); 41 41 for (unsigned i = 0; i < otherComponentCount; ++i) 42 42 new (NotNull, &m_selectorArray[i]) CSSSelector(other.m_selectorArray[i]); … … 44 44 45 45 CSSSelectorList::CSSSelectorList(CSSSelectorList&& other) 46 : m_selectorArray( other.m_selectorArray)46 : m_selectorArray(WTFMove(other.m_selectorArray)) 47 47 { 48 other.m_selectorArray = nullptr;49 48 } 50 49 … … 59 58 } 60 59 ASSERT(flattenedSize); 61 m_selectorArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * flattenedSize));60 m_selectorArray = makeUniqueArray<CSSSelector>(flattenedSize); 62 61 size_t arrayIndex = 0; 63 62 for (size_t i = 0; i < selectorVector.size(); ++i) { … … 88 87 if (!m_selectorArray) 89 88 return 0; 90 CSSSelector* current = m_selectorArray ;89 CSSSelector* current = m_selectorArray.get(); 91 90 while (!current->isLastInSelectorList()) 92 91 ++current; 93 return (current - m_selectorArray ) + 1;92 return (current - m_selectorArray.get()) + 1; 94 93 } 95 94 … … 99 98 return 0; 100 99 unsigned size = 1; 101 CSSSelector* current = m_selectorArray ;100 CSSSelector* current = m_selectorArray.get(); 102 101 while (!current->isLastInSelectorList()) { 103 102 if (current->isLastInTagHistory()) … … 110 109 CSSSelectorList& CSSSelectorList::operator=(CSSSelectorList&& other) 111 110 { 112 deleteSelectors(); 113 m_selectorArray = other.m_selectorArray; 114 other.m_selectorArray = nullptr; 115 111 m_selectorArray = WTFMove(other.m_selectorArray); 116 112 return *this; 117 }118 119 void CSSSelectorList::deleteSelectors()120 {121 if (!m_selectorArray)122 return;123 124 CSSSelector* selectorArray = m_selectorArray;125 m_selectorArray = nullptr;126 127 bool isLastSelector = false;128 for (CSSSelector* s = selectorArray; !isLastSelector; ++s) {129 isLastSelector = s->isLastInSelectorList();130 s->~CSSSelector();131 }132 fastFree(selectorArray);133 113 } 134 114 -
trunk/Source/WebCore/css/CSSSelectorList.h
r234814 r234825 28 28 #include "CSSSelector.h" 29 29 #include <memory> 30 #include <wtf/UniqueArray.h> 30 31 31 32 namespace WebCore { … … 36 37 WTF_MAKE_FAST_ALLOCATED; 37 38 public: 38 CSSSelectorList() : m_selectorArray(0) { }39 CSSSelectorList() = default; 39 40 CSSSelectorList(const CSSSelectorList&); 40 41 CSSSelectorList(CSSSelectorList&&); 41 42 CSSSelectorList(Vector<std::unique_ptr<CSSParserSelector>>&&); 42 43 ~CSSSelectorList() { deleteSelectors(); } 44 45 void adoptSelectorArray(CSSSelector* selectors) { ASSERT(!m_selectorArray); m_selectorArray = selectors; } 43 CSSSelectorList(UniqueArray<CSSSelector>&& array) 44 : m_selectorArray(WTFMove(array)) { } 46 45 47 46 bool isValid() const { return !!m_selectorArray; } 48 const CSSSelector* first() const { return m_selectorArray ; }47 const CSSSelector* first() const { return m_selectorArray.get(); } 49 48 static const CSSSelector* next(const CSSSelector*); 50 bool hasOneSelector() const { return m_selectorArray && !next(m_selectorArray); }51 49 const CSSSelector* selectorAt(size_t index) const { return &m_selectorArray[index]; } 52 50 … … 57 55 if (!current) 58 56 return notFound; 59 return current - m_selectorArray ;57 return current - m_selectorArray.get(); 60 58 } 61 59 … … 76 74 // End of a multipart selector is indicated by m_isLastInTagHistory bit in the last item. 77 75 // End of the array is indicated by m_isLastInSelectorList bit in the last item. 78 CSSSelector*m_selectorArray;76 UniqueArray<CSSSelector> m_selectorArray; 79 77 }; 80 78 -
trunk/Source/WebCore/css/CSSStyleRule.cpp
r218890 r234825 103 103 CSSStyleSheet::RuleMutationScope mutationScope(this); 104 104 105 m_styleRule->wrapperAdoptSelectorList( selectorList);105 m_styleRule->wrapperAdoptSelectorList(WTFMove(selectorList)); 106 106 107 107 if (hasCachedSelectorText()) { -
trunk/Source/WebCore/css/StyleRule.cpp
r228453 r234825 182 182 } 183 183 184 StyleRule::StyleRule(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin )184 StyleRule::StyleRule(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors) 185 185 : StyleRuleBase(Style, hasDocumentSecurityOrigin) 186 186 , m_properties(WTFMove(properties)) 187 , m_selectorList(WTFMove(selectors)) 187 188 { 188 189 } … … 214 215 { 215 216 ASSERT_WITH_SECURITY_IMPLICATION(!selectors.isEmpty()); 216 CSSSelector* selectorListArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * selectors.size()));217 auto selectorListArray = makeUniqueArray<CSSSelector>(selectors.size()); 217 218 for (unsigned i = 0; i < selectors.size(); ++i) 218 219 new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i)); 219 220 selectorListArray[selectors.size() - 1].setLastInSelectorList(); 220 auto rule = StyleRule::create(WTFMove(properties), hasDocumentSecurityOrigin); 221 rule.get().parserAdoptSelectorArray(selectorListArray); 222 return rule; 221 return StyleRule::create(WTFMove(properties), hasDocumentSecurityOrigin, WTFMove(selectorListArray)); 223 222 } 224 223 … … 249 248 } 250 249 251 StyleRulePage::StyleRulePage(Ref<StyleProperties>&& properties )250 StyleRulePage::StyleRulePage(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors) 252 251 : StyleRuleBase(Page) 253 252 , m_properties(WTFMove(properties)) 253 , m_selectorList(WTFMove(selectors)) 254 254 { 255 255 } -
trunk/Source/WebCore/css/StyleRule.h
r234814 r234825 119 119 WTF_MAKE_FAST_ALLOCATED; 120 120 public: 121 static Ref<StyleRule> create(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin )122 { 123 return adoptRef(*new StyleRule(WTFMove(properties), hasDocumentSecurityOrigin ));121 static Ref<StyleRule> create(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors) 122 { 123 return adoptRef(*new StyleRule(WTFMove(properties), hasDocumentSecurityOrigin, WTFMove(selectors))); 124 124 } 125 125 … … 134 134 using StyleRuleBase::hasDocumentSecurityOrigin; 135 135 136 void wrapperAdoptSelectorList(CSSSelectorList& selectors)136 void wrapperAdoptSelectorList(CSSSelectorList&& selectors) 137 137 { 138 138 m_selectorList = WTFMove(selectors); … … 141 141 #endif 142 142 } 143 void parserAdoptSelectorArray(CSSSelector* selectors) { m_selectorList.adoptSelectorArray(selectors); }144 143 145 144 Ref<StyleRule> copy() const { return adoptRef(*new StyleRule(*this)); } … … 163 162 164 163 private: 165 StyleRule(Ref<StylePropertiesBase>&&, bool hasDocumentSecurityOrigin );164 StyleRule(Ref<StylePropertiesBase>&&, bool hasDocumentSecurityOrigin, CSSSelectorList&&); 166 165 StyleRule(const StyleRule&); 167 166 … … 201 200 class StyleRulePage final : public StyleRuleBase { 202 201 public: 203 static Ref<StyleRulePage> create(Ref<StyleProperties>&& properties ) { return adoptRef(*new StyleRulePage(WTFMove(properties))); }202 static Ref<StyleRulePage> create(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors) { return adoptRef(*new StyleRulePage(WTFMove(properties), WTFMove(selectors))); } 204 203 205 204 ~StyleRulePage(); … … 209 208 MutableStyleProperties& mutableProperties(); 210 209 211 void wrapperAdoptSelectorList(CSSSelectorList& selectors) { m_selectorList = WTFMove(selectors); }210 void wrapperAdoptSelectorList(CSSSelectorList&& selectors) { m_selectorList = WTFMove(selectors); } 212 211 213 212 Ref<StyleRulePage> copy() const { return adoptRef(*new StyleRulePage(*this)); } 214 213 215 214 private: 216 explicit StyleRulePage(Ref<StyleProperties>&& );215 explicit StyleRulePage(Ref<StyleProperties>&&, CSSSelectorList&&); 217 216 StyleRulePage(const StyleRulePage&); 218 217 -
trunk/Source/WebCore/css/parser/CSSParserImpl.cpp
r234814 r234825 669 669 consumeDeclarationList(block, StyleRule::Style); 670 670 671 RefPtr<StyleRulePage> page = StyleRulePage::create(createStyleProperties(m_parsedProperties, m_context.mode)); 672 page->wrapperAdoptSelectorList(selectorList); 673 return page; 671 return StyleRulePage::create(createStyleProperties(m_parsedProperties, m_context.mode), WTFMove(selectorList)); 674 672 } 675 673 … … 727 725 return nullptr; // Parse error, invalid selector list 728 726 729 RefPtr<StyleRule> rule;730 727 if (m_observerWrapper) 731 728 observeSelectors(*m_observerWrapper, prelude); … … 739 736 blockCopy.consumeWhitespace(); 740 737 if (!blockCopy.atEnd()) { 741 rule = StyleRule::create(createDeferredStyleProperties(block), m_context.hasDocumentSecurityOrigin); 742 rule->wrapperAdoptSelectorList(selectorList); 743 return rule; 738 return StyleRule::create(createDeferredStyleProperties(block), m_context.hasDocumentSecurityOrigin, WTFMove(selectorList)); 744 739 } 745 740 } 746 741 747 742 consumeDeclarationList(block, StyleRule::Style); 748 rule = StyleRule::create(createStyleProperties(m_parsedProperties, m_context.mode), m_context.hasDocumentSecurityOrigin); 749 rule->wrapperAdoptSelectorList(selectorList); 750 return rule; 743 return StyleRule::create(createStyleProperties(m_parsedProperties, m_context.mode), m_context.hasDocumentSecurityOrigin, WTFMove(selectorList)); 751 744 } 752 745 -
trunk/Source/WebCore/css/parser/CSSSelectorParser.cpp
r234814 r234825 531 531 std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList()); 532 532 *selectorList = consumeComplexSelectorList(block); 533 if (!selectorList-> componentCount() || !block.atEnd())533 if (!selectorList->first() || !block.atEnd()) 534 534 return nullptr; 535 535 selector->setSelectorList(WTFMove(selectorList)); … … 560 560 std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList()); 561 561 *selectorList = consumeComplexSelectorList(block); 562 if (!selectorList-> componentCount() || !block.atEnd())562 if (!selectorList->first() || !block.atEnd()) 563 563 return nullptr; 564 564 selector->setSelectorList(WTFMove(selectorList)); … … 578 578 std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList()); 579 579 *selectorList = consumeComplexSelectorList(block); 580 if (!selectorList-> componentCount() || !block.atEnd())580 if (!selectorList->first() || !block.atEnd()) 581 581 return nullptr; 582 582 selector->setSelectorList(WTFMove(selectorList)); … … 587 587 std::unique_ptr<CSSSelectorList> selectorList = std::unique_ptr<CSSSelectorList>(new CSSSelectorList()); 588 588 *selectorList = consumeCompoundSelectorList(block); 589 if (!selectorList-> componentCount() || !block.atEnd())589 if (!selectorList->first() || !block.atEnd()) 590 590 return nullptr; 591 591 selector->setSelectorList(WTFMove(selectorList));
Note:
See TracChangeset
for help on using the changeset viewer.