diff options
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonobj.cpp | 6 | ||||
-rw-r--r-- | src/mongo/bson/bsonobj.h | 6 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp index 0149eeece7d..c462031bffd 100644 --- a/src/mongo/bson/bsonobj.cpp +++ b/src/mongo/bson/bsonobj.cpp @@ -129,6 +129,12 @@ BSONObj BSONObj::copy() const { return BSONObj(std::move(storage)); } +void BSONObj::makeOwned() { + if (!isOwned()) { + *this = copy(); + } +} + BSONObj BSONObj::getOwned() const { if (isOwned()) return *this; diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h index 1a51b370678..a0088c8b70d 100644 --- a/src/mongo/bson/bsonobj.h +++ b/src/mongo/bson/bsonobj.h @@ -265,6 +265,12 @@ public: BSONObj copy() const; /** + * If the data buffer is not under the control of this BSONObj, allocate + * a separate copy and make this object a fully owned one. + */ + void makeOwned(); + + /** * @return a new full (and owned) redacted copy of the object. */ BSONObj redact(bool onlyEncryptedFields = false) const; |