diff options
author | dwight <dwight@10gen.com> | 2010-10-27 12:39:00 -0400 |
---|---|---|
committer | dwight <dwight@10gen.com> | 2010-10-27 12:39:00 -0400 |
commit | e6e25269c22e7148054008e46a27afe0af2972b3 (patch) | |
tree | 18da1967177718aaff0402cacd51c279f99c2c2c /bson | |
parent | bad51fbd549f03c84ebe6bab124f61105a9207ee (diff) | |
download | mongo-e6e25269c22e7148054008e46a27afe0af2972b3.tar.gz |
optimization
Diffstat (limited to 'bson')
-rw-r--r-- | bson/bsoninlines.h | 13 | ||||
-rw-r--r-- | bson/bsonobj.h | 26 |
2 files changed, 18 insertions, 21 deletions
diff --git a/bson/bsoninlines.h b/bson/bsoninlines.h index 1142d08e8e3..deaad04caf9 100644 --- a/bson/bsoninlines.h +++ b/bson/bsoninlines.h @@ -47,6 +47,18 @@ namespace mongo { int strSizeWNull = *(int *)( value() + 4 ); return BSONObj( value() + 4 + 4 + strSizeWNull ); } + + inline NOINLINE_DECL void BSONObj::_assertInvalid() const { + StringBuilder ss; + int os = objsize(); + ss << "Invalid BSONObj size: " << os << " (0x" << toHex( &os, 4 ) << ')'; + try { + BSONElement e = firstElement(); + ss << " first element: " << e.toString(); + } + catch ( ... ) { } + massert( 10334 , ss.str() , 0 ); + } /* the idea with NOINLINE_DECL here is to keep this from inlining in the getOwned() method. the presumption being that is better. @@ -76,7 +88,6 @@ namespace mongo { return b.obj(); } - inline bool BSONObj::hasElement(const char *name) const { if ( !isEmpty() ) { BSONObjIterator it(*this); diff --git a/bson/bsonobj.h b/bson/bsonobj.h index 68069ddf114..4600c171fe1 100644 --- a/bson/bsonobj.h +++ b/bson/bsonobj.h @@ -78,8 +78,7 @@ namespace mongo { BSONObj(const Record *r); /** Construct an empty BSONObj -- that is, {}. */ BSONObj(); - // defensive - ~BSONObj() { _objdata = 0; } + ~BSONObj() { /*defensive:*/ _objdata = 0; } void appendSelfToBufBuilder(BufBuilder& b) const { assert( objsize() ); @@ -151,9 +150,7 @@ namespace mongo { } /** @return true if field exists */ - bool hasField( const char * name )const { - return ! getField( name ).eoo(); - } + bool hasField( const char * name ) const { return ! getField( name ).eoo(); } /** @return "" if DNE or wrong type */ const char * getStringField(const char *name) const; @@ -190,9 +187,7 @@ namespace mongo { return _objdata; } /** @return total size of the BSON object in bytes */ - int objsize() const { - return *(reinterpret_cast<const int*>(objdata())); - } + int objsize() const { return *(reinterpret_cast<const int*>(objdata())); } /** performs a cursory check on the object's size only. */ bool isValid(); @@ -362,22 +357,13 @@ private: const char *_objdata; boost::shared_ptr< Holder > _holder; + void _assertInvalid() const; void init(const char *data, bool ifree) { if ( ifree ) _holder.reset( new Holder( data ) ); _objdata = data; - if ( ! isValid() ){ - StringBuilder ss; - int os = objsize(); - ss << "Invalid BSONObj spec size: " << os << " (" << toHex( &os, 4 ) << ")"; - try { - BSONElement e = firstElement(); - ss << " first element:" << e.toString() << " "; - } - catch ( ... ){} - string s = ss.str(); - massert( 10334 , s , 0 ); - } + if ( !isValid() ) + _assertInvalid(); } }; ostream& operator<<( ostream &s, const BSONObj &o ); |