summaryrefslogtreecommitdiff
path: root/Source/WebCore/css/CSSValuePool.cpp
diff options
context:
space:
mode:
authorLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
committerLorry Tar Creator <lorry-tar-importer@lorry>2016-04-10 09:28:39 +0000
commit32761a6cee1d0dee366b885b7b9c777e67885688 (patch)
treed6bec92bebfb216f4126356e55518842c2f476a1 /Source/WebCore/css/CSSValuePool.cpp
parenta4e969f4965059196ca948db781e52f7cfebf19e (diff)
downloadWebKitGtk-tarball-32761a6cee1d0dee366b885b7b9c777e67885688.tar.gz
webkitgtk-2.4.11webkitgtk-2.4.11
Diffstat (limited to 'Source/WebCore/css/CSSValuePool.cpp')
-rw-r--r--Source/WebCore/css/CSSValuePool.cpp89
1 files changed, 45 insertions, 44 deletions
diff --git a/Source/WebCore/css/CSSValuePool.cpp b/Source/WebCore/css/CSSValuePool.cpp
index e7673774c..115bd9ba2 100644
--- a/Source/WebCore/css/CSSValuePool.cpp
+++ b/Source/WebCore/css/CSSValuePool.cpp
@@ -27,62 +27,54 @@
#include "CSSValuePool.h"
#include "CSSParser.h"
-#include "CSSPrimitiveValueMappings.h"
#include "CSSStyleSheet.h"
#include "CSSValueKeywords.h"
#include "CSSValueList.h"
namespace WebCore {
-CSSValuePool& CSSValuePool::singleton()
+CSSValuePool& cssValuePool()
{
- static NeverDestroyed<CSSValuePool> pool;
+ DEFINE_STATIC_LOCAL(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);
- }
}
-Ref<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident)
+PassRef<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSValueID ident)
{
- RELEASE_ASSERT(ident >= 0 && ident < numCSSValueKeywords);
- return m_identifierValues[ident].get();
+ 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];
}
-Ref<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident)
+PassRef<CSSPrimitiveValue> CSSValuePool::createIdentifierValue(CSSPropertyID ident)
{
return CSSPrimitiveValue::createIdentifier(ident);
}
-Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
+PassRef<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
{
// These are the empty and deleted values of the hash table.
if (rgbValue == Color::transparent)
- return m_transparentColor.get();
+ return m_colorTransparent.get();
if (rgbValue == Color::white)
- return m_whiteColor.get();
+ return m_colorWhite.get();
// Just because it is common.
if (rgbValue == Color::black)
- return m_blackColor.get();
+ return m_colorBlack.get();
// Remove one entry at random if the cache grows too large.
const int maximumColorCacheSize = 512;
@@ -95,10 +87,8 @@ Ref<CSSPrimitiveValue> CSSValuePool::createColorValue(unsigned rgbValue)
return *entry.iterator->value;
}
-Ref<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveValue::UnitTypes type)
+PassRef<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveValue::UnitTypes type)
{
- ASSERT(std::isfinite(value));
-
if (value < 0 || value > maximumCacheableIntegerValue)
return CSSPrimitiveValue::create(value, type);
@@ -106,29 +96,31 @@ Ref<CSSPrimitiveValue> CSSValuePool::createValue(double value, CSSPrimitiveValue
if (value != intValue)
return CSSPrimitiveValue::create(value, type);
+ RefPtr<CSSPrimitiveValue>* cache;
switch (type) {
case CSSPrimitiveValue::CSS_PX:
- return m_pixelValues[intValue].get();
+ cache = m_pixelValueCache;
+ break;
case CSSPrimitiveValue::CSS_PERCENTAGE:
- return m_percentValues[intValue].get();
+ cache = m_percentValueCache;
+ break;
case CSSPrimitiveValue::CSS_NUMBER:
- return m_numberValues[intValue].get();
+ cache = m_numberValueCache;
+ break;
default:
return CSSPrimitiveValue::create(value, type);
}
+
+ if (!cache[intValue])
+ cache[intValue] = CSSPrimitiveValue::create(value, type);
+ return *cache[intValue];
}
-Ref<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String& familyName, FromSystemFontID fromSystemFontID)
+PassRef<CSSPrimitiveValue> CSSValuePool::createFontFamilyValue(const String& familyName)
{
- // 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;
+ RefPtr<CSSPrimitiveValue>& value = m_fontFamilyValueCache.add(familyName, nullptr).iterator->value;
if (!value)
- value = CSSPrimitiveValue::create(CSSFontFamily{familyName, isFromSystemID});
+ value = CSSPrimitiveValue::create(familyName, CSSPrimitiveValue::CSS_STRING);
return *value;
}
@@ -150,6 +142,15 @@ 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;
+ }
}
}