Make CSSValuePool constructable
https://bugs.webkit.org/show_bug.cgi?id=204520
Patch by Chris Lord <clord@igalia.com> on 2019-11-22
Reviewed by Antti Koivisto.
No new tests, no new functionality.
* css/CSSInheritedValue.h:
* css/CSSRevertValue.h:
* css/CSSUnsetValue.h:
* css/CSSValuePool.cpp:
(WebCore::CSSValuePool::singleton):
(WebCore::CSSValuePool::CSSValuePool):
* css/CSSValuePool.h:
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@252785 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog
index 31dca91..d95fa55 100644
--- a/Source/WebCore/ChangeLog
+++ b/Source/WebCore/ChangeLog
@@ -1,3 +1,20 @@
+2019-11-22 Chris Lord <clord@igalia.com>
+
+ Make CSSValuePool constructable
+ https://bugs.webkit.org/show_bug.cgi?id=204520
+
+ Reviewed by Antti Koivisto.
+
+ No new tests, no new functionality.
+
+ * css/CSSInheritedValue.h:
+ * css/CSSRevertValue.h:
+ * css/CSSUnsetValue.h:
+ * css/CSSValuePool.cpp:
+ (WebCore::CSSValuePool::singleton):
+ (WebCore::CSSValuePool::CSSValuePool):
+ * css/CSSValuePool.h:
+
2019-11-22 Antti Koivisto <antti@apple.com>
Try to fix build on an old MacOS version
diff --git a/Source/WebCore/css/CSSInheritedValue.h b/Source/WebCore/css/CSSInheritedValue.h
index fbc070c..fa1bdd9 100644
--- a/Source/WebCore/css/CSSInheritedValue.h
+++ b/Source/WebCore/css/CSSInheritedValue.h
@@ -26,12 +26,13 @@
class CSSInheritedValue final : public CSSValue {
public:
+ static Ref<CSSInheritedValue> create() { return adoptRef(*new CSSInheritedValue()); }
+
String customCSSText() const;
bool equals(const CSSInheritedValue&) const { return true; }
private:
- friend LazyNeverDestroyed<CSSInheritedValue>;
CSSInheritedValue()
: CSSValue(InheritedClass)
{
diff --git a/Source/WebCore/css/CSSRevertValue.h b/Source/WebCore/css/CSSRevertValue.h
index 305b409..a126cbb 100644
--- a/Source/WebCore/css/CSSRevertValue.h
+++ b/Source/WebCore/css/CSSRevertValue.h
@@ -31,12 +31,13 @@
class CSSRevertValue final : public CSSValue {
public:
+ static Ref<CSSRevertValue> create() { return adoptRef(*new CSSRevertValue()); }
+
String customCSSText() const;
bool equals(const CSSRevertValue&) const { return true; }
private:
- friend LazyNeverDestroyed<CSSRevertValue>;
CSSRevertValue()
: CSSValue(RevertClass)
{
diff --git a/Source/WebCore/css/CSSUnsetValue.h b/Source/WebCore/css/CSSUnsetValue.h
index 2a494ed..5330518 100644
--- a/Source/WebCore/css/CSSUnsetValue.h
+++ b/Source/WebCore/css/CSSUnsetValue.h
@@ -31,12 +31,13 @@
class CSSUnsetValue final : public CSSValue {
public:
+ static Ref<CSSUnsetValue> create() { return adoptRef(*new CSSUnsetValue()); }
+
String customCSSText() const;
bool equals(const CSSUnsetValue&) const { return true; }
private:
- friend LazyNeverDestroyed<CSSUnsetValue>;
CSSUnsetValue()
: CSSValue(UnsetClass)
{
diff --git a/Source/WebCore/css/CSSValuePool.cpp b/Source/WebCore/css/CSSValuePool.cpp
index feeb8f1..125109b 100644
--- a/Source/WebCore/css/CSSValuePool.cpp
+++ b/Source/WebCore/css/CSSValuePool.cpp
@@ -35,29 +35,32 @@
CSSValuePool& CSSValuePool::singleton()
{
+ ASSERT(isMainThread());
static NeverDestroyed<CSSValuePool> pool;
return pool;
}
CSSValuePool::CSSValuePool()
+ : m_inheritedValue(CSSInheritedValue::create())
+ , m_implicitInitialValue(CSSInitialValue::createImplicit())
+ , m_explicitInitialValue(CSSInitialValue::createExplicit())
+ , m_unsetValue(CSSUnsetValue::create())
+ , m_revertValue(CSSRevertValue::create())
+ , m_transparentColor(CSSPrimitiveValue::create(Color(Color::transparent)))
+ , m_whiteColor(CSSPrimitiveValue::create(Color(Color::white)))
+ , m_blackColor(CSSPrimitiveValue::create(Color(Color::black)))
{
- m_inheritedValue.construct();
- m_implicitInitialValue.construct(true);
- m_explicitInitialValue.construct(false);
- m_unsetValue.construct();
- m_revertValue.construct();
+ m_identifierValues.reserveInitialCapacity(numCSSValueKeywords);
+ for (unsigned i = 0; i < numCSSValueKeywords; ++i)
+ m_identifierValues.uncheckedAppend(CSSPrimitiveValue::create(static_cast<CSSValueID>(i)));
- m_transparentColor.construct(Color(Color::transparent));
- m_whiteColor.construct(Color(Color::white));
- m_blackColor.construct(Color(Color::black));
-
- for (unsigned i = firstCSSValueKeyword; i <= lastCSSValueKeyword; ++i)
- m_identifierValues[i].construct(static_cast<CSSValueID>(i));
-
+ m_pixelValues.reserveInitialCapacity(maximumCacheableIntegerValue + 1);
+ m_percentValues.reserveInitialCapacity(maximumCacheableIntegerValue + 1);
+ m_numberValues.reserveInitialCapacity(maximumCacheableIntegerValue + 1);
for (unsigned i = 0; i < (maximumCacheableIntegerValue + 1); ++i) {
- m_pixelValues[i].construct(i, CSSUnitType::CSS_PX);
- m_percentValues[i].construct(i, CSSUnitType::CSS_PERCENTAGE);
- m_numberValues[i].construct(i, CSSUnitType::CSS_NUMBER);
+ m_pixelValues.uncheckedAppend(CSSPrimitiveValue::create(i, CSSUnitType::CSS_PX));
+ m_percentValues.uncheckedAppend(CSSPrimitiveValue::create(i, CSSUnitType::CSS_PERCENTAGE));
+ m_numberValues.uncheckedAppend(CSSPrimitiveValue::create(i, CSSUnitType::CSS_NUMBER));
}
}
diff --git a/Source/WebCore/css/CSSValuePool.h b/Source/WebCore/css/CSSValuePool.h
index 5857e1f..298c825 100644
--- a/Source/WebCore/css/CSSValuePool.h
+++ b/Source/WebCore/css/CSSValuePool.h
@@ -37,6 +37,7 @@
#include <wtf/HashMap.h>
#include <wtf/NeverDestroyed.h>
#include <wtf/RefPtr.h>
+#include <wtf/Vector.h>
#include <wtf/text/AtomStringHash.h>
namespace WebCore {
@@ -48,6 +49,8 @@
class CSSValuePool {
WTF_MAKE_FAST_ALLOCATED;
public:
+ CSSValuePool();
+
static CSSValuePool& singleton();
RefPtr<CSSValueList> createFontFaceValue(const AtomString&);
@@ -69,8 +72,6 @@
void drain();
private:
- CSSValuePool();
-
typedef HashMap<Color, RefPtr<CSSPrimitiveValue>> ColorValueCache;
ColorValueCache m_colorValueCache;
@@ -82,22 +83,22 @@
friend class WTF::NeverDestroyed<CSSValuePool>;
- LazyNeverDestroyed<CSSInheritedValue> m_inheritedValue;
- LazyNeverDestroyed<CSSInitialValue> m_implicitInitialValue;
- LazyNeverDestroyed<CSSInitialValue> m_explicitInitialValue;
- LazyNeverDestroyed<CSSUnsetValue> m_unsetValue;
- LazyNeverDestroyed<CSSRevertValue> m_revertValue;
+ Ref<CSSInheritedValue> m_inheritedValue;
+ Ref<CSSInitialValue> m_implicitInitialValue;
+ Ref<CSSInitialValue> m_explicitInitialValue;
+ Ref<CSSUnsetValue> m_unsetValue;
+ Ref<CSSRevertValue> m_revertValue;
- LazyNeverDestroyed<CSSPrimitiveValue> m_transparentColor;
- LazyNeverDestroyed<CSSPrimitiveValue> m_whiteColor;
- LazyNeverDestroyed<CSSPrimitiveValue> m_blackColor;
+ Ref<CSSPrimitiveValue> m_transparentColor;
+ Ref<CSSPrimitiveValue> m_whiteColor;
+ Ref<CSSPrimitiveValue> m_blackColor;
static const int maximumCacheableIntegerValue = 255;
- LazyNeverDestroyed<CSSPrimitiveValue> m_pixelValues[maximumCacheableIntegerValue + 1];
- LazyNeverDestroyed<CSSPrimitiveValue> m_percentValues[maximumCacheableIntegerValue + 1];
- LazyNeverDestroyed<CSSPrimitiveValue> m_numberValues[maximumCacheableIntegerValue + 1];
- LazyNeverDestroyed<CSSPrimitiveValue> m_identifierValues[numCSSValueKeywords];
+ Vector<Ref<CSSPrimitiveValue>> m_pixelValues;
+ Vector<Ref<CSSPrimitiveValue>> m_percentValues;
+ Vector<Ref<CSSPrimitiveValue>> m_numberValues;
+ Vector<Ref<CSSPrimitiveValue>> m_identifierValues;
};
} // namespace WebCore