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

Unified Diff: src/value-serializer.h

Issue 2492943002: ValueSerializer: Replace use of std::vector with a delegate-allocated buffer. (Closed)
Patch Set: correct comment 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
« no previous file with comments | « src/api.cc ('k') | src/value-serializer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/value-serializer.h
diff --git a/src/value-serializer.h b/src/value-serializer.h
index bb483dd7c874f066a971127beecc3533df4e52e9..86e21cf86cbf1eedfb4a94535fe1b8ce93865c95 100644
--- a/src/value-serializer.h
+++ b/src/value-serializer.h
@@ -59,7 +59,13 @@ class ValueSerializer {
* Returns the stored data. This serializer should not be used once the buffer
* is released. The contents are undefined if a previous write has failed.
*/
- std::vector<uint8_t> ReleaseBuffer() { return std::move(buffer_); }
+ std::vector<uint8_t> ReleaseBuffer();
+
+ /*
+ * Returns the buffer, allocated via the delegate, and its size.
+ * Caller assumes ownership of the buffer.
+ */
+ std::pair<uint8_t*, size_t> Release();
/*
* Marks an ArrayBuffer as havings its contents transferred out of band.
@@ -79,6 +85,9 @@ class ValueSerializer {
void WriteDouble(double value);
private:
+ // Managing allocations of the internal buffer.
+ void ExpandBuffer(size_t required_capacity);
+
// Writing the wire format.
void WriteTag(SerializationTag tag);
template <typename T>
@@ -126,7 +135,9 @@ class ValueSerializer {
Isolate* const isolate_;
v8::ValueSerializer::Delegate* const delegate_;
- std::vector<uint8_t> buffer_;
+ uint8_t* buffer_ = nullptr;
+ size_t buffer_size_ = 0;
+ size_t buffer_capacity_ = 0;
Zone zone_;
// To avoid extra lookups in the identity map, ID+1 is actually stored in the
« no previous file with comments | « src/api.cc ('k') | src/value-serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698