haikuwebkit/Source/WebCore/style/MatchedDeclarationsCache.cpp

160 lines
6.2 KiB
C++
Raw Permalink Normal View History

Factor matched declarations cache into a class https://bugs.webkit.org/show_bug.cgi?id=203972 Reviewed by Zalan Bujtas. Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache" to better describe it. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::declarationsForOrigin): Add a helper. (WebCore::ElementRuleCollector::transferMatchedRules): Reserve vector capacity before adding rules. (WebCore::ElementRuleCollector::addMatchedProperties): * css/ElementRuleCollector.h: (WebCore::MatchResult::operator== const): (WebCore::MatchResult::operator!= const): Remove the unneeded inline capacity so we can just use MatchResult itself in the cache. * css/RuleSet.cpp: (WebCore::RuleSet::addChildRules): * css/StyleResolver.cpp: (WebCore::StyleResolver::StyleResolver): (WebCore::StyleResolver::invalidateMatchedDeclarationsCache): (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits): (WebCore::StyleResolver::applyMatchedProperties): (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted. (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted. (WebCore::isCacheableInMatchedPropertiesCache): Deleted. * css/StyleResolver.h: (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted. * dom/Document.cpp: (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc): (WebCore::Document::updateViewportUnitsOnResize): * page/Page.cpp: (WebCore::Page::updateStyleAfterChangeInEnvironment): * style/MatchedDeclarationsCache.cpp: Added. (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache): (WebCore::Style::MatchedDeclarationsCache::isCacheable): (WebCore::Style::MatchedDeclarationsCache::computeHash): (WebCore::Style::MatchedDeclarationsCache::find): (WebCore::Style::MatchedDeclarationsCache::add): (WebCore::Style::MatchedDeclarationsCache::invalidate): (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits): (WebCore::Style::MatchedDeclarationsCache::sweep): * style/MatchedDeclarationsCache.h: Added. * style/StyleTreeResolver.cpp: (WebCore::Style::TreeResolver::resolveElement): Canonical link: https://commits.webkit.org/217306@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-07 23:01:20 +00:00
/*
* Copyright (C) 1999 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
* Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
* Copyright (C) 2005-2019 Apple Inc. All rights reserved.
* Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
* Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
* Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
* Copyright (c) 2011, Code Aurora Forum. All rights reserved.
* Copyright (C) Research In Motion Limited 2011. All rights reserved.
* Copyright (C) 2012, 2013 Google Inc. All rights reserved.
* Copyright (C) 2014 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "MatchedDeclarationsCache.h"
#include "CSSFontSelector.h"
#include "FontCascade.h"
Factor matched declarations cache into a class https://bugs.webkit.org/show_bug.cgi?id=203972 Reviewed by Zalan Bujtas. Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache" to better describe it. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::declarationsForOrigin): Add a helper. (WebCore::ElementRuleCollector::transferMatchedRules): Reserve vector capacity before adding rules. (WebCore::ElementRuleCollector::addMatchedProperties): * css/ElementRuleCollector.h: (WebCore::MatchResult::operator== const): (WebCore::MatchResult::operator!= const): Remove the unneeded inline capacity so we can just use MatchResult itself in the cache. * css/RuleSet.cpp: (WebCore::RuleSet::addChildRules): * css/StyleResolver.cpp: (WebCore::StyleResolver::StyleResolver): (WebCore::StyleResolver::invalidateMatchedDeclarationsCache): (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits): (WebCore::StyleResolver::applyMatchedProperties): (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted. (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted. (WebCore::isCacheableInMatchedPropertiesCache): Deleted. * css/StyleResolver.h: (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted. * dom/Document.cpp: (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc): (WebCore::Document::updateViewportUnitsOnResize): * page/Page.cpp: (WebCore::Page::updateStyleAfterChangeInEnvironment): * style/MatchedDeclarationsCache.cpp: Added. (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache): (WebCore::Style::MatchedDeclarationsCache::isCacheable): (WebCore::Style::MatchedDeclarationsCache::computeHash): (WebCore::Style::MatchedDeclarationsCache::find): (WebCore::Style::MatchedDeclarationsCache::add): (WebCore::Style::MatchedDeclarationsCache::invalidate): (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits): (WebCore::Style::MatchedDeclarationsCache::sweep): * style/MatchedDeclarationsCache.h: Added. * style/StyleTreeResolver.cpp: (WebCore::Style::TreeResolver::resolveElement): Canonical link: https://commits.webkit.org/217306@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-07 23:01:20 +00:00
#include <wtf/text/StringHash.h>
namespace WebCore {
namespace Style {
MatchedDeclarationsCache::MatchedDeclarationsCache()
: m_sweepTimer(*this, &MatchedDeclarationsCache::sweep)
{
}
MatchedDeclarationsCache::~MatchedDeclarationsCache() = default;
bool MatchedDeclarationsCache::isCacheable(const Element& element, const RenderStyle& style, const RenderStyle& parentStyle)
{
// FIXME: Writing mode and direction properties modify state when applying to document element by calling
// Document::setWritingMode/DirectionSetOnDocumentElement. We can't skip the applying by caching.
if (&element == element.document().documentElement())
return false;
// content:attr() value depends on the element it is being applied to.
if (style.hasAttrContent() || (style.styleType() != PseudoId::None && parentStyle.hasAttrContent()))
return false;
if (style.hasAppearance())
return false;
if (style.zoom() != RenderStyle::initialZoom())
return false;
if (style.writingMode() != RenderStyle::initialWritingMode() || style.direction() != RenderStyle::initialDirection())
return false;
// The cache assumes static knowledge about which properties are inherited.
if (style.hasExplicitlyInheritedProperties())
return false;
// Getting computed style after a font environment change but before full style resolution may involve styles with non-current fonts.
// Avoid caching them.
auto& fontSelector = element.document().fontSelector();
if (!style.fontCascade().isCurrent(fontSelector))
return false;
if (!parentStyle.fontCascade().isCurrent(fontSelector))
return false;
Factor matched declarations cache into a class https://bugs.webkit.org/show_bug.cgi?id=203972 Reviewed by Zalan Bujtas. Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache" to better describe it. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::declarationsForOrigin): Add a helper. (WebCore::ElementRuleCollector::transferMatchedRules): Reserve vector capacity before adding rules. (WebCore::ElementRuleCollector::addMatchedProperties): * css/ElementRuleCollector.h: (WebCore::MatchResult::operator== const): (WebCore::MatchResult::operator!= const): Remove the unneeded inline capacity so we can just use MatchResult itself in the cache. * css/RuleSet.cpp: (WebCore::RuleSet::addChildRules): * css/StyleResolver.cpp: (WebCore::StyleResolver::StyleResolver): (WebCore::StyleResolver::invalidateMatchedDeclarationsCache): (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits): (WebCore::StyleResolver::applyMatchedProperties): (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted. (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted. (WebCore::isCacheableInMatchedPropertiesCache): Deleted. * css/StyleResolver.h: (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted. * dom/Document.cpp: (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc): (WebCore::Document::updateViewportUnitsOnResize): * page/Page.cpp: (WebCore::Page::updateStyleAfterChangeInEnvironment): * style/MatchedDeclarationsCache.cpp: Added. (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache): (WebCore::Style::MatchedDeclarationsCache::isCacheable): (WebCore::Style::MatchedDeclarationsCache::computeHash): (WebCore::Style::MatchedDeclarationsCache::find): (WebCore::Style::MatchedDeclarationsCache::add): (WebCore::Style::MatchedDeclarationsCache::invalidate): (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits): (WebCore::Style::MatchedDeclarationsCache::sweep): * style/MatchedDeclarationsCache.h: Added. * style/StyleTreeResolver.cpp: (WebCore::Style::TreeResolver::resolveElement): Canonical link: https://commits.webkit.org/217306@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-07 23:01:20 +00:00
return true;
}
bool MatchedDeclarationsCache::Entry::isUsableAfterHighPriorityProperties(const RenderStyle& style) const
{
if (style.effectiveZoom() != renderStyle->effectiveZoom())
return false;
return CSSPrimitiveValue::equalForLengthResolution(style, *renderStyle);
}
Factor matched declarations cache into a class https://bugs.webkit.org/show_bug.cgi?id=203972 Reviewed by Zalan Bujtas. Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache" to better describe it. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::declarationsForOrigin): Add a helper. (WebCore::ElementRuleCollector::transferMatchedRules): Reserve vector capacity before adding rules. (WebCore::ElementRuleCollector::addMatchedProperties): * css/ElementRuleCollector.h: (WebCore::MatchResult::operator== const): (WebCore::MatchResult::operator!= const): Remove the unneeded inline capacity so we can just use MatchResult itself in the cache. * css/RuleSet.cpp: (WebCore::RuleSet::addChildRules): * css/StyleResolver.cpp: (WebCore::StyleResolver::StyleResolver): (WebCore::StyleResolver::invalidateMatchedDeclarationsCache): (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits): (WebCore::StyleResolver::applyMatchedProperties): (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted. (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted. (WebCore::isCacheableInMatchedPropertiesCache): Deleted. * css/StyleResolver.h: (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted. * dom/Document.cpp: (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc): (WebCore::Document::updateViewportUnitsOnResize): * page/Page.cpp: (WebCore::Page::updateStyleAfterChangeInEnvironment): * style/MatchedDeclarationsCache.cpp: Added. (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache): (WebCore::Style::MatchedDeclarationsCache::isCacheable): (WebCore::Style::MatchedDeclarationsCache::computeHash): (WebCore::Style::MatchedDeclarationsCache::find): (WebCore::Style::MatchedDeclarationsCache::add): (WebCore::Style::MatchedDeclarationsCache::invalidate): (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits): (WebCore::Style::MatchedDeclarationsCache::sweep): * style/MatchedDeclarationsCache.h: Added. * style/StyleTreeResolver.cpp: (WebCore::Style::TreeResolver::resolveElement): Canonical link: https://commits.webkit.org/217306@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-07 23:01:20 +00:00
unsigned MatchedDeclarationsCache::computeHash(const MatchResult& matchResult)
{
if (!matchResult.isCacheable)
return 0;
return StringHasher::hashMemory(matchResult.userAgentDeclarations.data(), sizeof(MatchedProperties) * matchResult.userAgentDeclarations.size())
^ StringHasher::hashMemory(matchResult.userDeclarations.data(), sizeof(MatchedProperties) * matchResult.userDeclarations.size())
^ StringHasher::hashMemory(matchResult.authorDeclarations.data(), sizeof(MatchedProperties) * matchResult.authorDeclarations.size());
}
const MatchedDeclarationsCache::Entry* MatchedDeclarationsCache::find(unsigned hash, const MatchResult& matchResult)
{
if (!hash)
return nullptr;
auto it = m_entries.find(hash);
if (it == m_entries.end())
return nullptr;
auto& entry = it->value;
if (matchResult != entry.matchResult)
return nullptr;
return &entry;
}
void MatchedDeclarationsCache::add(const RenderStyle& style, const RenderStyle& parentStyle, unsigned hash, const MatchResult& matchResult)
{
constexpr unsigned additionsBetweenSweeps = 100;
if (++m_additionsSinceLastSweep >= additionsBetweenSweeps && !m_sweepTimer.isActive()) {
constexpr auto sweepDelay = 1_min;
m_sweepTimer.startOneShot(sweepDelay);
}
ASSERT(hash);
// Note that we don't cache the original RenderStyle instance. It may be further modified.
// The RenderStyle in the cache is really just a holder for the substructures and never used as-is.
m_entries.add(hash, Entry { matchResult, RenderStyle::clonePtr(style), RenderStyle::clonePtr(parentStyle) });
}
void MatchedDeclarationsCache::invalidate()
{
m_entries.clear();
}
void MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits()
{
m_entries.removeIf([](auto& keyValue) {
return keyValue.value.renderStyle->hasViewportUnits();
});
}
void MatchedDeclarationsCache::sweep()
{
// Look for cache entries containing a style declaration with a single ref and remove them.
// This may happen when an element attribute mutation causes it to generate a new inlineStyle()
Rename presentationAttributeStyle to presentationalHintStyle to match spec language https://bugs.webkit.org/show_bug.cgi?id=226467 Reviewed by Sam Weinig. The HTML specification calls these "presentational hints", https://html.spec.whatwg.org/#presentational-hints. * dom/Attr.cpp: (WebCore::Attr::style): * dom/Element.cpp: (WebCore::Element::cloneAttributesFromElement): * dom/ElementData.cpp: (WebCore::ShareableElementData::ShareableElementData): (WebCore::UniqueElementData::UniqueElementData): * dom/ElementData.h: (WebCore::ElementData::presentationalHintStyleIsDirty const): (WebCore::ElementData::setPresentationalHintStyleIsDirty const): (WebCore::ElementData::presentationalHintStyle const): (WebCore::ElementData::presentationAttributeStyleIsDirty const): Deleted. (WebCore::ElementData::setPresentationAttributeStyleIsDirty const): Deleted. (WebCore::ElementData::presentationAttributeStyle const): Deleted. * dom/StyledElement.cpp: (WebCore::StyledElement::attributeChanged): (WebCore::StyledElement::rebuildPresentationalHintStyle): (WebCore::StyledElement::addPropertyToPresentationalHintStyle): (WebCore::StyledElement::rebuildPresentationAttributeStyle): Deleted. (WebCore::StyledElement::addPropertyToPresentationAttributeStyle): Deleted. * dom/StyledElement.h: (WebCore::StyledElement::collectPresentationalHintsForAttribute): (WebCore::StyledElement::additionalPresentationalHintStyle const): (WebCore::StyledElement::hasPresentationalHintsForAttribute const): (WebCore::StyledElement::presentationalHintStyle const): (WebCore::StyledElement::additionalPresentationAttributeStyle const): Deleted. (WebCore::StyledElement::collectStyleForPresentationAttribute): Deleted. (WebCore::StyledElement::isPresentationAttribute const): Deleted. (WebCore::StyledElement::presentationAttributeStyle const): Deleted. * html/HTMLBRElement.cpp: (WebCore::HTMLBRElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLBRElement::collectPresentationalHintsForAttribute): (WebCore::HTMLBRElement::isPresentationAttribute const): Deleted. (WebCore::HTMLBRElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLBRElement.h: * html/HTMLBodyElement.cpp: (WebCore::HTMLBodyElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLBodyElement::collectPresentationalHintsForAttribute): (WebCore::HTMLBodyElement::isPresentationAttribute const): Deleted. (WebCore::HTMLBodyElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLBodyElement.h: * html/HTMLButtonElement.cpp: (WebCore::HTMLButtonElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLButtonElement::isPresentationAttribute const): Deleted. * html/HTMLButtonElement.h: * html/HTMLDivElement.cpp: (WebCore::HTMLDivElement::collectPresentationalHintsForAttribute): (WebCore::HTMLDivElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLDivElement.h: * html/HTMLElement.cpp: (WebCore::HTMLElement::applyBorderAttributeToStyle): (WebCore::HTMLElement::mapLanguageAttributeToLocale): (WebCore::HTMLElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLElement::collectPresentationalHintsForAttribute): (WebCore::HTMLElement::applyAlignmentAttributeToStyle): (WebCore::HTMLElement::addHTMLLengthToStyle): (WebCore::HTMLElement::isPresentationAttribute const): Deleted. (WebCore::HTMLElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLElement.h: * html/HTMLEmbedElement.cpp: (WebCore::HTMLEmbedElement::collectPresentationalHintsForAttribute): (WebCore::HTMLEmbedElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLEmbedElement.h: * html/HTMLFontElement.cpp: (WebCore::HTMLFontElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLFontElement::collectPresentationalHintsForAttribute): (WebCore::HTMLFontElement::isPresentationAttribute const): Deleted. (WebCore::HTMLFontElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLFontElement.h: * html/HTMLFrameSetElement.cpp: (WebCore::HTMLFrameSetElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLFrameSetElement::collectPresentationalHintsForAttribute): (WebCore::HTMLFrameSetElement::isPresentationAttribute const): Deleted. (WebCore::HTMLFrameSetElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLFrameSetElement.h: * html/HTMLHRElement.cpp: (WebCore::HTMLHRElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLHRElement::collectPresentationalHintsForAttribute): (WebCore::HTMLHRElement::isPresentationAttribute const): Deleted. (WebCore::HTMLHRElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLHRElement.h: * html/HTMLIFrameElement.cpp: (WebCore::HTMLIFrameElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLIFrameElement::collectPresentationalHintsForAttribute): (WebCore::HTMLIFrameElement::isPresentationAttribute const): Deleted. (WebCore::HTMLIFrameElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLIFrameElement.h: * html/HTMLImageElement.cpp: (WebCore::HTMLImageElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLImageElement::collectPresentationalHintsForAttribute): (WebCore::HTMLImageElement::isPresentationAttribute const): Deleted. (WebCore::HTMLImageElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLImageElement.h: * html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLInputElement::collectPresentationalHintsForAttribute): (WebCore::HTMLInputElement::isPresentationAttribute const): Deleted. (WebCore::HTMLInputElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLInputElement.h: * html/HTMLLIElement.cpp: (WebCore::HTMLLIElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLLIElement::collectPresentationalHintsForAttribute): (WebCore::HTMLLIElement::isPresentationAttribute const): Deleted. (WebCore::HTMLLIElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLLIElement.h: * html/HTMLMarqueeElement.cpp: (WebCore::HTMLMarqueeElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLMarqueeElement::collectPresentationalHintsForAttribute): (WebCore::HTMLMarqueeElement::isPresentationAttribute const): Deleted. (WebCore::HTMLMarqueeElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLMarqueeElement.h: * html/HTMLOListElement.cpp: (WebCore::HTMLOListElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLOListElement::collectPresentationalHintsForAttribute): (WebCore::HTMLOListElement::isPresentationAttribute const): Deleted. (WebCore::HTMLOListElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLOListElement.h: * html/HTMLObjectElement.cpp: (WebCore::HTMLObjectElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLObjectElement::collectPresentationalHintsForAttribute): (WebCore::HTMLObjectElement::isPresentationAttribute const): Deleted. (WebCore::HTMLObjectElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLObjectElement.h: * html/HTMLParagraphElement.cpp: (WebCore::HTMLParagraphElement::collectPresentationalHintsForAttribute): (WebCore::HTMLParagraphElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLParagraphElement.h: * html/HTMLPlugInElement.cpp: (WebCore::HTMLPlugInElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLPlugInElement::collectPresentationalHintsForAttribute): (WebCore::HTMLPlugInElement::isPresentationAttribute const): Deleted. (WebCore::HTMLPlugInElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLPlugInElement.h: * html/HTMLPreElement.cpp: (WebCore::HTMLPreElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLPreElement::collectPresentationalHintsForAttribute): (WebCore::HTMLPreElement::isPresentationAttribute const): Deleted. (WebCore::HTMLPreElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLPreElement.h: * html/HTMLSelectElement.cpp: (WebCore::HTMLSelectElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLSelectElement::isPresentationAttribute const): Deleted. * html/HTMLSelectElement.h: * html/HTMLTableCaptionElement.cpp: (WebCore::HTMLTableCaptionElement::collectPresentationalHintsForAttribute): (WebCore::HTMLTableCaptionElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLTableCaptionElement.h: * html/HTMLTableCellElement.cpp: (WebCore::HTMLTableCellElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLTableCellElement::collectPresentationalHintsForAttribute): (WebCore::HTMLTableCellElement::additionalPresentationalHintStyle const): (WebCore::HTMLTableCellElement::isPresentationAttribute const): Deleted. (WebCore::HTMLTableCellElement::collectStyleForPresentationAttribute): Deleted. (WebCore::HTMLTableCellElement::additionalPresentationAttributeStyle const): Deleted. * html/HTMLTableCellElement.h: * html/HTMLTableColElement.cpp: (WebCore::HTMLTableColElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLTableColElement::collectPresentationalHintsForAttribute): (WebCore::HTMLTableColElement::additionalPresentationalHintStyle const): (WebCore::HTMLTableColElement::isPresentationAttribute const): Deleted. (WebCore::HTMLTableColElement::collectStyleForPresentationAttribute): Deleted. (WebCore::HTMLTableColElement::additionalPresentationAttributeStyle const): Deleted. * html/HTMLTableColElement.h: * html/HTMLTableElement.cpp: (WebCore::HTMLTableElement::collectPresentationalHintsForAttribute): (WebCore::HTMLTableElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLTableElement::additionalPresentationalHintStyle const): (WebCore::HTMLTableElement::collectStyleForPresentationAttribute): Deleted. (WebCore::HTMLTableElement::isPresentationAttribute const): Deleted. (WebCore::HTMLTableElement::additionalPresentationAttributeStyle const): Deleted. * html/HTMLTableElement.h: * html/HTMLTablePartElement.cpp: (WebCore::HTMLTablePartElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLTablePartElement::collectPresentationalHintsForAttribute): (WebCore::HTMLTablePartElement::isPresentationAttribute const): Deleted. (WebCore::HTMLTablePartElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLTablePartElement.h: * html/HTMLTableSectionElement.cpp: (WebCore::HTMLTableSectionElement::additionalPresentationalHintStyle const): (WebCore::HTMLTableSectionElement::additionalPresentationAttributeStyle const): Deleted. * html/HTMLTableSectionElement.h: * html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLTextAreaElement::collectPresentationalHintsForAttribute): (WebCore::HTMLTextAreaElement::isPresentationAttribute const): Deleted. (WebCore::HTMLTextAreaElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLTextAreaElement.h: * html/HTMLTextFormControlElement.cpp: (WebCore::HTMLTextFormControlElement::adjustInnerTextStyle const): * html/HTMLUListElement.cpp: (WebCore::HTMLUListElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLUListElement::collectPresentationalHintsForAttribute): (WebCore::HTMLUListElement::isPresentationAttribute const): Deleted. (WebCore::HTMLUListElement::collectStyleForPresentationAttribute): Deleted. * html/HTMLUListElement.h: * html/HTMLVideoElement.cpp: (WebCore::HTMLVideoElement::collectPresentationalHintsForAttribute): (WebCore::HTMLVideoElement::hasPresentationalHintsForAttribute const): (WebCore::HTMLVideoElement::collectStyleForPresentationAttribute): Deleted. (WebCore::HTMLVideoElement::isPresentationAttribute const): Deleted. * html/HTMLVideoElement.h: * inspector/agents/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::buildObjectForAttributesStyle): * mathml/MathMLElement.cpp: (WebCore::MathMLElement::hasPresentationalHintsForAttribute const): (WebCore::MathMLElement::collectPresentationalHintsForAttribute): (WebCore::MathMLElement::isPresentationAttribute const): Deleted. (WebCore::MathMLElement::collectStyleForPresentationAttribute): Deleted. * mathml/MathMLElement.h: * style/ElementRuleCollector.cpp: (WebCore::Style::ElementRuleCollector::matchAllRules): * style/MatchedDeclarationsCache.cpp: (WebCore::Style::MatchedDeclarationsCache::sweep): * style/StyleSharingResolver.cpp: (WebCore::Style::SharingResolver::canShareStyleWithElement const): (WebCore::Style::SharingResolver::sharingCandidateHasIdenticalStyleAffectingAttributes const): * svg/SVGCircleElement.cpp: (WebCore::SVGCircleElement::svgAttributeChanged): * svg/SVGElement.cpp: (WebCore::SVGElement::hasPresentationalHintsForAttribute const): (WebCore::SVGElement::collectPresentationalHintsForAttribute): (WebCore::SVGElement::isPresentationAttribute const): Deleted. (WebCore::SVGElement::collectStyleForPresentationAttribute): Deleted. * svg/SVGElement.h: (WebCore::SVGElement::invalidateSVGPresentationalHintStyle): (WebCore::SVGElement::invalidateSVGPresentationAttributeStyle): Deleted. * svg/SVGEllipseElement.cpp: (WebCore::SVGEllipseElement::svgAttributeChanged): * svg/SVGFilterElement.cpp: (WebCore::SVGFilterElement::svgAttributeChanged): * svg/SVGForeignObjectElement.cpp: (WebCore::SVGForeignObjectElement::svgAttributeChanged): * svg/SVGImageElement.cpp: (WebCore::SVGImageElement::svgAttributeChanged): * svg/SVGMaskElement.cpp: (WebCore::SVGMaskElement::svgAttributeChanged): * svg/SVGPatternElement.cpp: (WebCore::SVGPatternElement::svgAttributeChanged): * svg/SVGRectElement.cpp: (WebCore::SVGRectElement::svgAttributeChanged): * svg/SVGSVGElement.cpp: (WebCore::SVGSVGElement::svgAttributeChanged): * svg/SVGTextContentElement.cpp: (WebCore::SVGTextContentElement::hasPresentationalHintsForAttribute const): (WebCore::SVGTextContentElement::collectPresentationalHintsForAttribute): (WebCore::SVGTextContentElement::isPresentationAttribute const): Deleted. (WebCore::SVGTextContentElement::collectStyleForPresentationAttribute): Deleted. * svg/SVGTextContentElement.h: * svg/SVGTextPositioningElement.cpp: (WebCore::SVGTextPositioningElement::collectPresentationalHintsForAttribute): (WebCore::SVGTextPositioningElement::hasPresentationalHintsForAttribute const): (WebCore::SVGTextPositioningElement::collectStyleForPresentationAttribute): Deleted. (WebCore::SVGTextPositioningElement::isPresentationAttribute const): Deleted. * svg/SVGTextPositioningElement.h: * svg/properties/SVGAttributeAnimator.cpp: (WebCore::SVGAttributeAnimator::invalidateStyle): Canonical link: https://commits.webkit.org/238314@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@278277 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2021-05-31 15:02:54 +00:00
// or presentationalHintStyle(), potentially leaving this cache with the last ref on the old one.
Factor matched declarations cache into a class https://bugs.webkit.org/show_bug.cgi?id=203972 Reviewed by Zalan Bujtas. Move the code out from StyleResolver and rename "matched properties cache" -> "matched declarations cache" to better describe it. * Sources.txt: * WebCore.xcodeproj/project.pbxproj: * css/ElementRuleCollector.cpp: (WebCore::ElementRuleCollector::declarationsForOrigin): Add a helper. (WebCore::ElementRuleCollector::transferMatchedRules): Reserve vector capacity before adding rules. (WebCore::ElementRuleCollector::addMatchedProperties): * css/ElementRuleCollector.h: (WebCore::MatchResult::operator== const): (WebCore::MatchResult::operator!= const): Remove the unneeded inline capacity so we can just use MatchResult itself in the cache. * css/RuleSet.cpp: (WebCore::RuleSet::addChildRules): * css/StyleResolver.cpp: (WebCore::StyleResolver::StyleResolver): (WebCore::StyleResolver::invalidateMatchedDeclarationsCache): (WebCore::StyleResolver::clearCachedDeclarationsAffectedByViewportUnits): (WebCore::StyleResolver::applyMatchedProperties): (WebCore::StyleResolver::sweepMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::computeMatchedPropertiesHash): Deleted. (WebCore::StyleResolver::findFromMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::addToMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::invalidateMatchedPropertiesCache): Deleted. (WebCore::StyleResolver::clearCachedPropertiesAffectedByViewportUnits): Deleted. (WebCore::isCacheableInMatchedPropertiesCache): Deleted. * css/StyleResolver.h: (WebCore::StyleResolver::MatchedPropertiesCacheItem::MatchedPropertiesCacheItem): Deleted. * dom/Document.cpp: (WebCore::Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc): (WebCore::Document::updateViewportUnitsOnResize): * page/Page.cpp: (WebCore::Page::updateStyleAfterChangeInEnvironment): * style/MatchedDeclarationsCache.cpp: Added. (WebCore::Style::MatchedDeclarationsCache::MatchedDeclarationsCache): (WebCore::Style::MatchedDeclarationsCache::isCacheable): (WebCore::Style::MatchedDeclarationsCache::computeHash): (WebCore::Style::MatchedDeclarationsCache::find): (WebCore::Style::MatchedDeclarationsCache::add): (WebCore::Style::MatchedDeclarationsCache::invalidate): (WebCore::Style::MatchedDeclarationsCache::clearEntriesAffectedByViewportUnits): (WebCore::Style::MatchedDeclarationsCache::sweep): * style/MatchedDeclarationsCache.h: Added. * style/StyleTreeResolver.cpp: (WebCore::Style::TreeResolver::resolveElement): Canonical link: https://commits.webkit.org/217306@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@252208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-11-07 23:01:20 +00:00
auto hasOneRef = [](auto& declarations) {
for (auto& matchedProperties : declarations) {
if (matchedProperties.properties->hasOneRef())
return true;
}
return false;
};
m_entries.removeIf([&](auto& keyValue) {
auto& matchResult = keyValue.value.matchResult;
return hasOneRef(matchResult.userAgentDeclarations) || hasOneRef(matchResult.userDeclarations) || hasOneRef(matchResult.authorDeclarations);
});
m_additionsSinceLastSweep = 0;
}
}
}