Use intrusive_ptr rather than shared_ptr for BSONObj
Advantages: * Owned BSONObj now uses 1 heap allocation rather than 3 * sizeof(BSONObj) is now 16 rather than 24 (on 64 bit) * perftest bson shows it to be much faster Change in BSONObj constructor API for owned case to make sure old code gets updated to allocate room for the ref count. Anyone using BSONObjBuilder doesn't need to worry about this change.
This commit is contained in:
@@ -405,15 +405,17 @@ namespace mongo {
|
||||
if ( guess == 0 )
|
||||
return BSONObj();
|
||||
|
||||
char * buf = (char *) malloc(guess);
|
||||
jobject bb = _getEnv()->NewDirectByteBuffer( (void*)buf , guess );
|
||||
BSONObj::Holder* holder = (BSONObj::Holder*) malloc(guess + sizeof(unsigned));
|
||||
holder->zero()
|
||||
|
||||
jobject bb = _getEnv()->NewDirectByteBuffer( (void*)holder->data , guess );
|
||||
jassert( bb );
|
||||
|
||||
int len = _getEnv()->CallStaticIntMethod( _dbhook , _scopeGetObject , id , _getEnv()->NewStringUTF( field ) , bb );
|
||||
_getEnv()->DeleteLocalRef( bb );
|
||||
jassert( len > 0 && len < guess );
|
||||
|
||||
BSONObj obj(buf, true);
|
||||
BSONObj obj(holder);
|
||||
assert( obj.objsize() <= guess );
|
||||
return obj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user