summaryrefslogtreecommitdiff
path: root/src/mongo/bson/util
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-08-26 18:40:48 -0400
committerMathias Stearn <mathias@10gen.com>2016-08-29 15:34:16 -0400
commitd6d263b0c8fe21ac9bfca561515dccbe02f72e64 (patch)
tree60ea8f2057591bb46967276ca7d6f34588446f9c /src/mongo/bson/util
parent2374ef1a3ac05e3fca39485ef4824f559b1c082c (diff)
downloadmongo-d6d263b0c8fe21ac9bfca561515dccbe02f72e64.tar.gz
SERVER-23100 Allow StringBuilder and str::stream to return StringData views
Avoids unnecessary copies when passing result to a function.
Diffstat (limited to 'src/mongo/bson/util')
-rw-r--r--src/mongo/bson/util/builder.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/mongo/bson/util/builder.h b/src/mongo/bson/util/builder.h
index e6d29ceb175..258e63cf52d 100644
--- a/src/mongo/bson/util/builder.h
+++ b/src/mongo/bson/util/builder.h
@@ -446,6 +446,15 @@ public:
return std::string(_buf.buf(), _buf.l);
}
+ /**
+ * Returns a view of this string without copying.
+ *
+ * WARNING: the view expires when this StringBuilder is modified or destroyed.
+ */
+ StringData stringData() const {
+ return StringData(_buf.buf(), _buf.l);
+ }
+
/** size of current std::string */
int len() const {
return _buf.l;