[SERVER-1271] BSONObjBuilder and BSONArrayBuilder chould have a 'done' method that does not return a BSONObj Created: 21/Jun/10  Updated: 12/Jul/16  Resolved: 27/Jul/10

Status: Closed
Project: Core Server
Component/s: Internal Client
Affects Version/s: 1.5.3
Fix Version/s: 1.5.7

Type: Improvement Priority: Major - P3
Reporter: Andrew Morrow (Inactive) Assignee: Alberto Lerner
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

All


Participants:

 Description   

Its frequently the case that you construct a subobject for which you have no interest in the resulting BSONObj, since you only care about the BSONObj for the top level. It would be nice if there was a way to get the "done" behavior, but not spend time constructing a BSONObj just to throw it away. FWIW, the call to BSONObj::init that results from a call to 'done' is not inlined in my build:

{
const boost::scoped_ptr<mongo::BSONArrayBuilder> delete_builder( m_builder );
m_builder->done(); // no interest in return value
}

generates the following on my machine (compiled with optimization of course):

202310: 53 push %rbx
202311: 48 83 ec 40 sub $0x40,%rsp
202315: 48 8b 7f 08 mov 0x8(%rdi),%rdi
202319: 48 89 7c 24 30 mov %rdi,0x30(%rsp)
20231e: 48 83 c7 08 add $0x8,%rdi
202322: e8 a9 25 00 00 callq 2048d0 <mongo::BSONObjBuilder::_done()>
202327: 48 8d 5c 24 10 lea 0x10(%rsp),%rbx
20232c: 31 d2 xor %edx,%edx
20232e: 48 89 c6 mov %rax,%rsi
202331: 48 c7 44 24 18 00 00 movq $0x0,0x18(%rsp)
202338: 00 00
20233a: 48 c7 44 24 20 00 00 movq $0x0,0x20(%rsp)
202341: 00 00
202343: 48 89 df mov %rbx,%rdi
202346: e8 e5 70 fe ff callq 1e9430 <mongo::BSONObj::init(char const*, bool)>
//...

There is no need for that call to BSONObj::init (inlined or not, not to mention any other construction / destruction code) in this use case.



 Comments   
Comment by Alberto Lerner [ 27/Jul/10 ]

Thanks Andrew Morrow for pointing out the issue and contributing the fix!

Comment by Alberto Lerner [ 27/Jul/10 ]

Author:

{'login': 'acm', 'name': 'Andrew Morrow', 'email': 'andrew.c.morrow@gmail.com'}

fast done capability for BSONObjBuilder
http://github.com/mongodb/mongo/commit/8443231430a20f75b6d44760d87c00fe761b2bc6

Generated at Thu Feb 08 02:56:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.