Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Unified Diff: third_party/WebKit/Source/core/css/StylePropertySet.cpp

Issue 1481383002: [Experimental] CSSSerializer Proof-of-concept Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: snapshot: top_25 sites ser/dser now works Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/css/StylePropertySet.cpp
diff --git a/third_party/WebKit/Source/core/css/StylePropertySet.cpp b/third_party/WebKit/Source/core/css/StylePropertySet.cpp
index 04da3ec817a457dbd5b40ff50f6c7899b34ec82f..6f3381334eafa841b915ed3b129ca006568ed33e 100644
--- a/third_party/WebKit/Source/core/css/StylePropertySet.cpp
+++ b/third_party/WebKit/Source/core/css/StylePropertySet.cpp
@@ -29,6 +29,8 @@
#include "core/css/StylePropertySerializer.h"
#include "core/css/StyleSheetContents.h"
#include "core/css/parser/CSSParser.h"
+#include "core/css/serializer/CSSDeserializeStream.h"
+#include "core/css/serializer/CSSSerializeStream.h"
#include "core/frame/UseCounter.h"
#include "platform/RuntimeEnabledFeatures.h"
#include "wtf/text/StringBuilder.h"
@@ -56,6 +58,21 @@ PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::cre
return adoptRefWillBeNoop(new (slot) ImmutableStylePropertySet(properties, count, cssParserMode));
}
+PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> ImmutableStylePropertySet::deserialize(CSSDeserializeStream* stream)
+{
+ unsigned count = stream->readUnsigned();
+ CSSParserMode cssParserMode = HTMLStandardMode; // FIXME!!!
+ CSDEBUG("ImmutableStylePropertySet::deserialize count: %u\n", count);
+
+ ASSERT(count <= MaxArraySize);
+#if ENABLE(OILPAN)
+ void* slot = Heap::allocate<StylePropertySet>(sizeForImmutableStylePropertySetWithPropertyCount(count));
+#else
+ void* slot = WTF::Partitions::fastMalloc(sizeForImmutableStylePropertySetWithPropertyCount(count), "blink::ImmutableStylePropertySet");
+#endif // ENABLE(OILPAN)
+ return adoptRefWillBeNoop(new (slot) ImmutableStylePropertySet(stream, count, cssParserMode));
+}
+
PassRefPtrWillBeRawPtr<ImmutableStylePropertySet> StylePropertySet::immutableCopyIfNeeded() const
{
if (!isMutable())
@@ -91,6 +108,22 @@ ImmutableStylePropertySet::ImmutableStylePropertySet(const CSSProperty* properti
}
}
+ImmutableStylePropertySet::ImmutableStylePropertySet(CSSDeserializeStream* stream, unsigned length, CSSParserMode cssParserMode)
+ : StylePropertySet(cssParserMode, length)
+{
+ StylePropertyMetadata* metadataArray = const_cast<StylePropertyMetadata*>(this->metadataArray());
+ RawPtrWillBeMember<CSSValue>* valueArray = const_cast<RawPtrWillBeMember<CSSValue>*>(this->valueArray());
+ for (unsigned i = 0; i < m_arraySize; ++i) {
+ metadataArray[i] = stream->readStylePropertyMetadata();
+ }
+ for (unsigned i = 0; i < m_arraySize; ++i) {
+ valueArray[i] = CSSValue::deserialize(stream).leakRef();
+#if !ENABLE(OILPAN)
+ valueArray[i]->ref(); // FIXME: maybe not needed as above "leaks"
+#endif
+ }
+}
+
ImmutableStylePropertySet::~ImmutableStylePropertySet()
{
#if !ENABLE(OILPAN)
@@ -145,6 +178,23 @@ int ImmutableStylePropertySet::findPropertyIndex(T property) const
template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(CSSPropertyID) const;
template CORE_EXPORT int ImmutableStylePropertySet::findPropertyIndex(AtomicString) const;
+void ImmutableStylePropertySet::serializeAfterDispatch(CSSSerializeStream* stream) const
+{
+ // FIXME: handle CSSParserMode
+ stream->writeUnsigned(m_arraySize);
+ CSDEBUG("ImmutableStylePropertySet::serializeAfterDispatch count: %u\n", m_arraySize);
+
+ auto metadatas = metadataArray();
+ for (unsigned i = 0; i < m_arraySize; i++) {
+ stream->writeStylePropertyMetadata(metadatas[i]);
+ }
+
+ const RawPtrWillBeMember<CSSValue>* values = valueArray();
+ for (unsigned i = 0; i < m_arraySize; i++) {
+ values[i]->serialize(stream);
+ }
+}
+
DEFINE_TRACE_AFTER_DISPATCH(ImmutableStylePropertySet)
{
const RawPtrWillBeMember<CSSValue>* values = valueArray();
@@ -561,6 +611,14 @@ DEFINE_TRACE_AFTER_DISPATCH(MutableStylePropertySet)
StylePropertySet::traceAfterDispatch(visitor);
}
+void StylePropertySet::serialize(CSSSerializeStream* stream) const
+{
+ CSDEBUG("StylePropertySet::serialize\n");
+
+ ASSERT(!m_isMutable);
+ toImmutableStylePropertySet(this)->serializeAfterDispatch(stream);
+}
+
unsigned StylePropertySet::averageSizeInBytes()
{
// Please update this if the storage scheme changes so that this longer reflects the actual size.
« no previous file with comments | « third_party/WebKit/Source/core/css/StylePropertySet.h ('k') | third_party/WebKit/Source/core/css/StyleRule.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698