Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-1271

BSONObjBuilder and BSONArrayBuilder chould have a 'done' method that does not return a BSONObj

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 1.5.7
    • Affects Version/s: 1.5.3
    • Component/s: Internal Client
    • None
    • Environment:
      All

      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.

            Assignee:
            alerner Alberto Lerner
            Reporter:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: