summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonobjbuilder.h
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2016-06-06 14:08:29 -0400
committerMathias Stearn <mathias@10gen.com>2016-06-22 16:04:36 -0400
commite508ddcb51eec941ae50d9c2efb06b601811dc19 (patch)
treecab51e8665c29d8220b64e7f69a8bbc592ca5339 /src/mongo/bson/bsonobjbuilder.h
parent40f20eca105a5e06a72df583ac654f946e9b058e (diff)
downloadmongo-e508ddcb51eec941ae50d9c2efb06b601811dc19.tar.gz
SERVER-24418 Make Message and BufBuilder use SharedBuffer for memory management
This makes it possible to get owned BSONObj out of a Message without copying. Hooked up to the following places: - Anything using the Fetcher (including oplog fetching on secondaries) - Anything using DBClientInterface::findOne() - Anything using CursorResponse (including Sharded queries) As a simplification, Messages no longer support non-contiguous buffers, or non-owning buffers. The former wasn't used by anything, and the latter was only used by mongosniff only for messages that fit in a single packet.
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder.h')
-rw-r--r--src/mongo/bson/bsonobjbuilder.h24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.h b/src/mongo/bson/bsonobjbuilder.h
index 10b8a93b80e..224deb1ee6d 100644
--- a/src/mongo/bson/bsonobjbuilder.h
+++ b/src/mongo/bson/bsonobjbuilder.h
@@ -65,15 +65,8 @@ class BSONObjBuilder {
public:
/** @param initsize this is just a hint as to the final size of the object */
BSONObjBuilder(int initsize = 512)
- : _b(_buf),
- _buf(sizeof(BSONObj::Holder) + initsize),
- _offset(sizeof(BSONObj::Holder)),
- _s(this),
- _tracker(0),
- _doneCalled(false) {
- // Skip over space for a holder object at the beginning of the buffer, followed by
- // space for the object length. The length is filled in by _done.
- _b.skip(sizeof(BSONObj::Holder));
+ : _b(_buf), _buf(initsize), _offset(0), _s(this), _tracker(0), _doneCalled(false) {
+ // Skip over space for the object length. The length is filled in by _done.
_b.skip(sizeof(int));
// Reserve space for the EOO byte. This means _done() can't fail.
@@ -119,13 +112,12 @@ public:
BSONObjBuilder(const BSONSizeTracker& tracker)
: _b(_buf),
- _buf(sizeof(BSONObj::Holder) + tracker.getSize()),
- _offset(sizeof(BSONObj::Holder)),
+ _buf(tracker.getSize()),
+ _offset(0),
_s(this),
_tracker(const_cast<BSONSizeTracker*>(&tracker)),
_doneCalled(false) {
// See the comments in the first constructor for details.
- _b.skip(sizeof(BSONObj::Holder));
_b.skip(sizeof(int));
// Reserve space for the EOO byte. This means _done() can't fail.
@@ -639,9 +631,7 @@ public:
BSONObj obj() {
massert(10335, "builder does not own memory", owned());
doneFast();
- char* buf = _b.buf();
- decouple();
- return BSONObj::takeOwnership(buf);
+ return BSONObj(_b.release());
}
/** Fetch the object we have built.
@@ -681,10 +671,6 @@ public:
_doneCalled = true;
}
- void decouple() {
- _b.decouple(); // post done() call version. be sure jsobj frees...
- }
-
void appendKeys(const BSONObj& keyPattern, const BSONObj& values);
static std::string numStr(int i) {