diff options
author | Konstantin Tokarev <annulen@yandex.ru> | 2016-08-25 19:20:41 +0300 |
---|---|---|
committer | Konstantin Tokarev <annulen@yandex.ru> | 2017-02-02 12:30:55 +0000 |
commit | 6882a04fb36642862b11efe514251d32070c3d65 (patch) | |
tree | b7959826000b061fd5ccc7512035c7478742f7b0 /Source/WebCore/css/CSSValuePool.cpp | |
parent | ab6df191029eeeb0b0f16f127d553265659f739e (diff) | |
download | qtwebkit-6882a04fb36642862b11efe514251d32070c3d65.tar.gz |
Imported QtWebKit TP3 (git b57bc6801f1876c3220d5a4bfea33d620d477443)
Change-Id: I3b1d8a2808782c9f34d50240000e20cb38d3680f
Reviewed-by: Konstantin Tokarev <annulen@yandex.ru>
Diffstat (limited to 'Source/WebCore/css/CSSValuePool.cpp')
-rw-r--r-- | Source/WebCore/css/CSSValuePool.cpp | 110 |
1 files changed, 54 insertions, 56 deletions
diff --git a/Source/WebCore/css/CSSValuePool.cpp b/Source/WebCore/css/CSSValuePool.cpp index 855682693..e7673774c 100644 --- a/Source/WebCore/css/CSSValuePool.cpp +++ b/Source/WebCore/css/CSSValuePool.cpp @@ -27,69 +27,78 @@ #include "CSSValuePool.h" #include "CSSParser.h" +#include "CSSPrimitiveValueMappings.h" #include "CSSStyleSheet.h" #include "CSSValueKeywords.h" #include "CSSValueList.h" namespace WebCore { -CSSValuePool& cssValuePool() +CSSValuePool& CSSValuePool::singleton() { - DEFINE_STATIC_LOCAL(CSSValuePool, pool, ()); + static NeverDestroyed<CSSValuePool> pool; return pool; } CSSValuePool::CSSValuePool() - : m_inheritedValue(CSSInheritedValue::create()) - , m_implicitInitialValue(CSSInitialValue::createImplicit()) - , m_explicitInitialValue(CSSInitialValue::createExplicit()) - , m_colorTransparent(CSSPrimitiveValue::createColor(Color::transparent)) - , m_colorWhite(CSSPrimitiveValue::createColor(Color::white)) - , m_colorBlack(CSSPrimitiveValue::createColor(Color::black)) { + m_inheritedValue.construct(); + m_implicitInitialValue.construct(true); + m_explicitInitialValue.construct(false); + m_unsetValue.construct(); + m_revertValue.construct(); + + m_transparentColor.construct(Color::transparent); + m_whiteColor.construct(Color::white); + m_blackColor.construct(Color::black); + + for (unsigned i = 0; i < numCSSValueKeywords; ++i) + m_identifierValues[i].construct(static_cast<CSSValueID>(i)); + + for (unsigned i = 0; i < (maximumCacheableIntegerValue + 1); ++i) { + m_pixelValues[i].construct(i, CSSPrimitiveValue::CSS_PX); + m_percentValues[i].construct(i, CSSPrimitiveValue::CSS_PERCENTAGE); + m_numberValues[i].construct(i, CSSPrimitiveValue::CSS_NUMBER); + } } -PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident) +Ref<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident) { - if (!ident) - return CSSPrimitiveValue::createIdentifier(ident); - - RELEASE_ASSERT(ident > 0 && ident < numCSSValueKeywords); - if (!m_identifierValueCache[ident]) - m_identifierValueCache[ident] = CSSPrimitiveValue::createIdentifier(ident); - return m_identifierValueCache[ident]; + RELEASE_ASSERT(ident >= 0 && ident < numCSSValueKeywords); + return m_identifierValues[ident].get(); } -PassRefPtr<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident) +Ref<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident) { return CSSPrimitiveValue::createIdentifier(ident); } -PassRefPtr<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue) +Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue) { // These are the empty and deleted values of the hash table. if (rgbValue == Color::transparent) - return m_colorTransparent; + return m_transparentColor.get(); if (rgbValue == Color::white) - return m_colorWhite; + return m_whiteColor.get(); // Just because it is common. if (rgbValue == Color::black) - return m_colorBlack; + return m_blackColor.get(); - // Just wipe out the cache and start rebuilding if it gets too big. + // Remove one entry at random if the cache grows too large. const int maximumColorCacheSize = 512; - if (m_colorValueCache.size() > maximumColorCacheSize) - m_colorValueCache.clear(); + if (m_colorValueCache.size() >= maximumColorCacheSize) + m_colorValueCache.remove(m_colorValueCache.begin()); - RefPtr<CSSPrimitiveValue> dummyValue; - ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, dummyValue); + ColorValueCache::AddResult entry = m_colorValueCache.add(rgbValue, nullptr); if (entry.isNewEntry) entry.iterator->value = CSSPrimitiveValue::createColor(rgbValue); - return entry.iterator->value; + return *entry.iterator->value; } -PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveValue::UnitTypes type) +Ref<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveValue::UnitTypes type) { + ASSERT(std::isfinite(value)); + if (value < 0 || value > maximumCacheableIntegerValue) return CSSPrimitiveValue::create(value, type); @@ -97,42 +106,40 @@ PassRefPtr<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimiti if (value != intValue) return CSSPrimitiveValue::create(value, type); - RefPtr<CSSPrimitiveValue>* cache; switch (type) { case CSSPrimitiveValue::CSS_PX: - cache = m_pixelValueCache; - break; + return m_pixelValues[intValue].get(); case CSSPrimitiveValue::CSS_PERCENTAGE: - cache = m_percentValueCache; - break; + return m_percentValues[intValue].get(); case CSSPrimitiveValue::CSS_NUMBER: - cache = m_numberValueCache; - break; + return m_numberValues[intValue].get(); default: return CSSPrimitiveValue::create(value, type); } - - if (!cache[intValue]) - cache[intValue] = CSSPrimitiveValue::create(value, type); - return cache[intValue]; } -PassRefPtr<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String& familyName) +Ref<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String& familyName, FromSystemFontID fromSystemFontID) { - RefPtr<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(familyName, 0).iterator->value; + // Remove one entry at random if the cache grows too large. + const int maximumFontFamilyCacheSize = 128; + if (m_fontFamilyValueCache.size() >= maximumFontFamilyCacheSize) + m_fontFamilyValueCache.remove(m_fontFamilyValueCache.begin()); + + bool isFromSystemID = fromSystemFontID == FromSystemFontID::Yes; + RefPtr<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add({familyName, isFromSystemID}, nullptr).iterator->value; if (!value) - value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STRING); - return value; + value = CSSPrimitiveValue::create(CSSFontFamily{familyName, isFromSystemID}); + return *value; } PassRefPtr<CSSValueList> CSSValuePool::createFontFaceValue(const AtomicString& string) { - // Just wipe out the cache and start rebuilding if it gets too big. + // Remove one entry at random if the cache grows too large. const int maximumFontFaceCacheSize = 128; - if (m_fontFaceValueCache.size() > maximumFontFaceCacheSize) - m_fontFaceValueCache.clear(); + if (m_fontFaceValueCache.size() >= maximumFontFaceCacheSize) + m_fontFaceValueCache.remove(m_fontFaceValueCache.begin()); - RefPtr<CSSValueList>& value = m_fontFaceValueCache.add(string, 0).iterator->value; + RefPtr<CSSValueList>& value = m_fontFaceValueCache.add(string, nullptr).iterator->value; if (!value) value = CSSParser::parseFontFaceValue(string); return value; @@ -143,15 +150,6 @@ void CSSValuePool::drain() m_colorValueCache.clear(); m_fontFaceValueCache.clear(); m_fontFamilyValueCache.clear(); - - for (int i = 0; i < numCSSValueKeywords; ++i) - m_identifierValueCache[i] = 0; - - for (int i = 0; i < maximumCacheableIntegerValue; ++i) { - m_pixelValueCache[i] = 0; - m_percentValueCache[i] = 0; - m_numberValueCache[i] = 0; - } } } |