diff options
author | Mathias Stearn <mathias@10gen.com> | 2019-04-24 18:18:39 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2019-05-01 19:14:20 -0400 |
commit | f6d863188b71b420f13b8249579d34de76d80d9c (patch) | |
tree | 3d1de115082ca8bde41e6b9029b2bbb1d6e4cbb9 /src/mongo/bson/bsonobjbuilder.cpp | |
parent | 3ca7cf08c389d877f4e427012533fa0785d96d10 (diff) | |
download | mongo-f6d863188b71b420f13b8249579d34de76d80d9c.tar.gz |
SERVER-40802 move some expensive and commonly instantiated functions out of line
Diffstat (limited to 'src/mongo/bson/bsonobjbuilder.cpp')
-rw-r--r-- | src/mongo/bson/bsonobjbuilder.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobjbuilder.cpp b/src/mongo/bson/bsonobjbuilder.cpp index cd928af0f9f..dc607e14726 100644 --- a/src/mongo/bson/bsonobjbuilder.cpp +++ b/src/mongo/bson/bsonobjbuilder.cpp @@ -228,6 +228,17 @@ bool BSONObjBuilder::hasField(StringData name) const { return false; } +BSONObjBuilder::~BSONObjBuilder() { + // If 'done' has not already been called, and we have a reference to an owning + // BufBuilder but do not own it ourselves, then we must call _done to write in the + // length. Otherwise, we own this memory and its lifetime ends with us, therefore + // we can elide the write. + if (!_doneCalled && _b.buf() && _buf.getSize() == 0) { + _done(); + } +} + + const string BSONObjBuilder::numStrs[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", @@ -244,4 +255,25 @@ const string BSONObjBuilder::numStrs[] = { // numStrs is initialized because it is a static variable bool BSONObjBuilder::numStrsReady = (numStrs[0].size() > 0); +template <typename Alloc> +void _BufBuilder<Alloc>::grow_reallocate(int minSize) { + if (minSize > BufferMaxSize) { + std::stringstream ss; + ss << "BufBuilder attempted to grow() to " << minSize << " bytes, past the 64MB limit."; + msgasserted(13548, ss.str().c_str()); + } + + int a = 64; + while (a < minSize) + a = a * 2; + + _buf.realloc(a); + size = a; +} + +template class _BufBuilder<SharedBufferAllocator>; +template class _BufBuilder<StackAllocator>; +template class StringBuilderImpl<SharedBufferAllocator>; +template class StringBuilderImpl<StackAllocator>; + } // namespace mongo |