Index: net/base/io_buffer.h |
diff --git a/net/base/io_buffer.h b/net/base/io_buffer.h |
index 0ce52e8d79c02473adabd6af98e2e9272d9b2fdb..df8eb5e37951e61f5f4881b2524512220492a477 100644 |
--- a/net/base/io_buffer.h |
+++ b/net/base/io_buffer.h |
@@ -123,6 +123,22 @@ class NET_EXPORT StringIOBuffer : public IOBuffer { |
std::string string_data_; |
}; |
+// This version allows a string to be used as the storage for a write-style |
+// operation, avoiding an extra data copy. The string passed to the constructor |
+// is std::string::swap'd with an interal string. |
+class NET_EXPORT ZeroCopyStringIOBuffer : public IOBuffer { |
gavinp
2014/08/14 22:02:45
Firstly, this is really cool. Well thought out and
jkarlin
2014/08/15 00:13:34
Great suggestion. Done.
|
+ public: |
+ // The input |s| is swapped with string_. |
+ ZeroCopyStringIOBuffer(std::string* s); |
+ |
+ std::string* string() { return &string_; } |
+ |
+ private: |
+ virtual ~ZeroCopyStringIOBuffer(); |
+ |
+ std::string string_; |
+}; |
+ |
// This version wraps an existing IOBuffer and provides convenient functions |
// to progressively read all the data. |
// |