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

Unified Diff: third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp

Issue 2494823002: V8ScriptValueSerializer: Use PartitionAlloc for the buffer, and avoid copying it into a String. (Closed)
Patch Set: initialize SerializedScriptValue::m_dataBufferSize Created 4 years, 1 month 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/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp
diff --git a/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp b/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp
index 9c45b714f853d1c5e25fabb94259ccb87109fb60..efbea512af30df75084538e0da90e533a6c1d602 100644
--- a/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp
+++ b/third_party/WebKit/Source/bindings/core/v8/serialization/V8ScriptValueSerializer.cpp
@@ -19,6 +19,7 @@
#include "public/platform/WebBlobInfo.h"
#include "wtf/AutoReset.h"
#include "wtf/DateMath.h"
+#include "wtf/allocator/Partitions.h"
#include "wtf/text/StringUTF8Adaptor.h"
namespace blink {
@@ -63,13 +64,9 @@ RefPtr<SerializedScriptValue> V8ScriptValueSerializer::serialize(
return nullptr;
// Finalize the results.
- std::vector<uint8_t> buffer = m_serializer.ReleaseBuffer();
- // Currently, the output must be padded to a multiple of two bytes.
- // TODO(jbroman): Remove this old conversion to WTF::String.
- if (buffer.size() % 2)
- buffer.push_back(0);
+ std::pair<uint8_t*, size_t> buffer = m_serializer.Release();
m_serializedScriptValue->setData(
- String(reinterpret_cast<const UChar*>(&buffer[0]), buffer.size() / 2));
+ SerializedScriptValue::DataBufferPtr(buffer.first), buffer.second);
return std::move(m_serializedScriptValue);
}
@@ -372,4 +369,16 @@ v8::Maybe<bool> V8ScriptValueSerializer::WriteHostObject(
return v8::Nothing<bool>();
}
+void* V8ScriptValueSerializer::ReallocateBufferMemory(void* oldBuffer,
+ size_t size,
+ size_t* actualSize) {
+ *actualSize = WTF::Partitions::bufferActualSize(size);
+ return WTF::Partitions::bufferRealloc(oldBuffer, size,
+ "SerializedScriptValue buffer");
+}
+
+void V8ScriptValueSerializer::FreeBufferMemory(void* buffer) {
+ return WTF::Partitions::bufferFree(buffer);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698