Permalink
Browse files

a small maybe optimization

  • Loading branch information...
1 parent ac2dc24 commit c11fceb8f1b8c1f2df5c0a6735dd6d7109c275f5 @dwight dwight committed Oct 26, 2010
Showing with 14 additions and 10 deletions.
  1. +10 −1 bson/bsoninlines.h
  2. +4 −9 bson/bsonobj.h
View
@@ -48,12 +48,21 @@ namespace mongo {
return BSONObj( value() + 4 + 4 + strSizeWNull );
}
- inline BSONObj BSONObj::copy() const {
+ /* the idea with NOINLINE_DECL here is to keep this from inlining in the
+ getOwned() method. the presumption being that is better.
+ */
+ inline NOINLINE_DECL BSONObj BSONObj::copy() const {
char *p = (char*) malloc(objsize());
memcpy(p, objdata(), objsize());
return BSONObj(p, true);
}
+ inline BSONObj BSONObj::getOwned() const {
+ if ( isOwned() )
+ return *this;
+ return copy();
+ }
+
// wrap this element up as a singleton object.
inline BSONObj BSONElement::wrap() const {
BSONObjBuilder b(size()+6);
View
@@ -251,9 +251,7 @@ namespace mongo {
}
/** @return first field of the object */
- BSONElement firstElement() const {
- return BSONElement(objdata() + 4);
- }
+ BSONElement firstElement() const { return BSONElement(objdata() + 4); }
/** @return true if field exists in the object */
bool hasElement(const char *name) const;
@@ -265,15 +263,12 @@ namespace mongo {
*/
bool getObjectID(BSONElement& e) const;
- /** makes a copy of the object. */
+ /** @return a new full copy of the object. */
BSONObj copy() const;
/* make sure the data buffer is under the control of this BSONObj and not a remote buffer */
- BSONObj getOwned() const{
- if ( !isOwned() )
- return copy();
- return *this;
- }
+ BSONObj getOwned() const;
+
bool isOwned() const { return _holder.get() != 0; }
/** @return A hash code for the object */

0 comments on commit c11fceb

Please sign in to comment.