| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/css/parser/CSSLazyParsingState.h" | 5 #include "core/css/parser/CSSLazyParsingState.h" |
| 6 #include "core/css/parser/CSSLazyPropertyParserImpl.h" | 6 #include "core/css/parser/CSSLazyPropertyParserImpl.h" |
| 7 #include "core/css/parser/CSSParserTokenRange.h" | 7 #include "core/css/parser/CSSParserTokenRange.h" |
| 8 #include "core/dom/Document.h" | 8 #include "core/dom/Document.h" |
| 9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
| 10 #include "platform/Histogram.h" | 10 #include "platform/Histogram.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext* context, | 14 CSSLazyParsingState::CSSLazyParsingState(const CSSParserContext* context, |
| 15 Vector<String> escapedStrings, | 15 Vector<String> escapedStrings, |
| 16 const String& sheetText, | 16 const String& sheetText, |
| 17 StyleSheetContents* contents) | 17 StyleSheetContents* contents) |
| 18 : m_context(context), | 18 : m_context(context), |
| 19 m_escapedStrings(std::move(escapedStrings)), | |
| 20 m_sheetText(sheetText), | 19 m_sheetText(sheetText), |
| 21 m_owningContents(contents), | 20 m_owningContents(contents), |
| 22 m_parsedStyleRules(0), | 21 m_parsedStyleRules(0), |
| 23 m_totalStyleRules(0), | 22 m_totalStyleRules(0), |
| 24 m_styleRulesNeededForNextMilestone(0), | 23 m_styleRulesNeededForNextMilestone(0), |
| 25 m_usage(UsageGe0), | 24 m_usage(UsageGe0), |
| 26 m_shouldUseCount(m_context->isUseCounterRecordingEnabled()) {} | 25 m_shouldUseCount(m_context->isUseCounterRecordingEnabled()) { |
| 26 m_escapedStrings.reserveCapacityForSize(escapedStrings.size()); |
| 27 for (const auto& escapedString : escapedStrings) { |
| 28 m_escapedStrings.insert(escapedString.impl()->bytes(), escapedString); |
| 29 } |
| 30 } |
| 27 | 31 |
| 28 void CSSLazyParsingState::finishInitialParsing() { | 32 void CSSLazyParsingState::finishInitialParsing() { |
| 29 recordUsageMetrics(); | 33 recordUsageMetrics(); |
| 30 } | 34 } |
| 31 | 35 |
| 32 CSSLazyPropertyParserImpl* CSSLazyParsingState::createLazyParser( | 36 CSSLazyPropertyParserImpl* CSSLazyParsingState::createLazyParser( |
| 33 const CSSParserTokenRange& block) { | 37 const CSSParserTokenRange& block) { |
| 34 ++m_totalStyleRules; | 38 ++m_totalStyleRules; |
| 35 return new CSSLazyPropertyParserImpl(std::move(block), this); | 39 return new CSSLazyPropertyParserImpl(std::move(block), this); |
| 36 } | 40 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 const CSSSelector::PseudoType type(current->getPseudoType()); | 86 const CSSSelector::PseudoType type(current->getPseudoType()); |
| 83 if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter) | 87 if (type == CSSSelector::PseudoBefore || type == CSSSelector::PseudoAfter) |
| 84 return false; | 88 return false; |
| 85 if (current->relation() != CSSSelector::SubSelector) | 89 if (current->relation() != CSSSelector::SubSelector) |
| 86 break; | 90 break; |
| 87 } | 91 } |
| 88 } | 92 } |
| 89 return true; | 93 return true; |
| 90 } | 94 } |
| 91 | 95 |
| 96 bool CSSLazyParsingState::tokenBackingUsesEscapedString( |
| 97 const void* tokenBackingBytes) { |
| 98 return m_escapedStrings.contains(tokenBackingBytes); |
| 99 } |
| 100 |
| 92 void CSSLazyParsingState::recordUsageMetrics() { | 101 void CSSLazyParsingState::recordUsageMetrics() { |
| 93 DEFINE_STATIC_LOCAL(EnumerationHistogram, usageHistogram, | 102 DEFINE_STATIC_LOCAL(EnumerationHistogram, usageHistogram, |
| 94 ("Style.LazyUsage.Percent", UsageLastValue)); | 103 ("Style.LazyUsage.Percent", UsageLastValue)); |
| 95 DEFINE_STATIC_LOCAL(CustomCountHistogram, totalRulesHistogram, | 104 DEFINE_STATIC_LOCAL(CustomCountHistogram, totalRulesHistogram, |
| 96 ("Style.TotalLazyRules", 0, 100000, 50)); | 105 ("Style.TotalLazyRules", 0, 100000, 50)); |
| 97 DEFINE_STATIC_LOCAL(CustomCountHistogram, totalRulesFullUsageHistogram, | 106 DEFINE_STATIC_LOCAL(CustomCountHistogram, totalRulesFullUsageHistogram, |
| 98 ("Style.TotalLazyRules.FullUsage", 0, 100000, 50)); | 107 ("Style.TotalLazyRules.FullUsage", 0, 100000, 50)); |
| 99 switch (m_usage) { | 108 switch (m_usage) { |
| 100 case UsageGe0: | 109 case UsageGe0: |
| 101 totalRulesHistogram.count(m_totalStyleRules); | 110 totalRulesHistogram.count(m_totalStyleRules); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 125 usageHistogram.count(m_usage); | 134 usageHistogram.count(m_usage); |
| 126 } | 135 } |
| 127 | 136 |
| 128 DEFINE_TRACE(CSSLazyParsingState) { | 137 DEFINE_TRACE(CSSLazyParsingState) { |
| 129 visitor->trace(m_owningContents); | 138 visitor->trace(m_owningContents); |
| 130 visitor->trace(m_document); | 139 visitor->trace(m_document); |
| 131 visitor->trace(m_context); | 140 visitor->trace(m_context); |
| 132 } | 141 } |
| 133 | 142 |
| 134 } // namespace blink | 143 } // namespace blink |
| OLD | NEW |