void cleanCache(TimerBase* timer) { DCHECK_EQ(timer, &m_cleanTimer); unsigned hitCount = m_hitCount; m_hitCount = 0; if (hitCount > minimumPresentationAttributeCacheHitCountPerMinute) return; presentationAttributeCache().clear(); }
void StyledElement::rebuildPresentationAttributeStyle() { PresentationAttributeCacheKey cacheKey; makePresentationAttributeCacheKey(cacheKey); unsigned cacheHash = computePresentationAttributeCacheHash(cacheKey); PresentationAttributeCache::iterator cacheIterator; if (cacheHash) { cacheIterator = presentationAttributeCache().add(cacheHash, nullptr).iterator; if (cacheIterator->value && cacheIterator->value->key != cacheKey) cacheHash = 0; } else cacheIterator = presentationAttributeCache().end(); RefPtr<StyleProperties> style; if (cacheHash && cacheIterator->value) { style = cacheIterator->value->value; presentationAttributeCacheCleaner().didHitPresentationAttributeCache(); } else { style = MutableStyleProperties::create(isSVGElement() ? SVGAttributeMode : CSSQuirksMode); for (const Attribute& attribute : attributesIterator()) collectStyleForPresentationAttribute(attribute.name(), attribute.value(), static_cast<MutableStyleProperties&>(*style)); } // ShareableElementData doesn't store presentation attribute style, so make sure we have a UniqueElementData. UniqueElementData& elementData = ensureUniqueElementData(); elementData.setPresentationAttributeStyleIsDirty(false); elementData.m_presentationAttributeStyle = style->isEmpty() ? 0 : style; if (!cacheHash || cacheIterator->value) return; std::unique_ptr<PresentationAttributeCacheEntry> newEntry = std::make_unique<PresentationAttributeCacheEntry>(); newEntry->key = cacheKey; newEntry->value = style.release(); static const int presentationAttributeCacheMaximumSize = 4096; if (presentationAttributeCache().size() > presentationAttributeCacheMaximumSize) { // Start building from scratch if the cache ever gets big. presentationAttributeCache().clear(); presentationAttributeCache().set(cacheHash, WTF::move(newEntry)); } else cacheIterator->value = WTF::move(newEntry); }
void cleanCache(Timer<PresentationAttributeCacheCleaner>* timer) { ASSERT_UNUSED(timer, timer == &m_cleanTimer); unsigned hitCount = m_hitCount; m_hitCount = 0; if (hitCount > minimumPresentationAttributeCacheHitCountPerMinute) return; presentationAttributeCache().clear(); }
void didHitPresentationAttributeCache() { if (presentationAttributeCache().size() < minimumPresentationAttributeCacheSizeForCleaning) return; m_hitCount++; if (!m_cleanTimer.isActive()) m_cleanTimer.startOneShot(presentationAttributeCacheCleanTimeInSeconds); }