diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-04-28 14:43:50 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-04-28 15:35:43 -0400 |
commit | 377281fd326ece7cb48675662f34b9148b40e000 (patch) | |
tree | a31d80a1ecd8b317e2c57b4316f8ec92cb5339ce | |
parent | e787a11b714635b83637072d07d11da45b4f43c0 (diff) | |
download | mongo-377281fd326ece7cb48675662f34b9148b40e000.tar.gz |
SERVER-28508 Reserve space in OpMsgReplyBuilder::getInPlaceReplyBuilder
This avoids excess realloc() calls when processing getMore commands.
-rw-r--r-- | src/mongo/rpc/op_msg_rpc_impls.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/mongo/rpc/op_msg_rpc_impls.h b/src/mongo/rpc/op_msg_rpc_impls.h index b98107cac0f..f99d8b0f93c 100644 --- a/src/mongo/rpc/op_msg_rpc_impls.h +++ b/src/mongo/rpc/op_msg_rpc_impls.h @@ -61,7 +61,12 @@ public: return *this; } BSONObjBuilder getInPlaceReplyBuilder(std::size_t reserveBytes) override { - return _builder.beginBody(); + BSONObjBuilder bob = _builder.beginBody(); + // Eagerly reserve space and claim our reservation immediately so we can actually write data + // to it. + bob.bb().reserveBytes(reserveBytes); + bob.bb().claimReservedBytes(reserveBytes); + return bob; } ReplyBuilderInterface& setMetadata(const BSONObj& metadata) override { _builder.resumeBody().appendElements(metadata); |