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:
Mathias Stearn
2011-04-01 17:35:11 -04:00
parent a67334a286
commit 244b162111
11 changed files with 72 additions and 42 deletions

View File

@@ -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;
}