diff options
author | Ruoxin Xu <ruoxin.xu@mongodb.com> | 2020-08-31 10:57:29 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-22 13:33:33 +0000 |
commit | 13096e75c224d4ab7231a8788005c41fee8d7991 (patch) | |
tree | c158e1d498f9d00536629ee11e8123e14322b16c /src/mongo/bson/bsonobj.h | |
parent | 2e51850ef5456cfaa7f43fe271c78bcc5f399104 (diff) | |
download | mongo-13096e75c224d4ab7231a8788005c41fee8d7991.tar.gz |
SERVER-49817 Optimize document diffing code
Diffstat (limited to 'src/mongo/bson/bsonobj.h')
-rw-r--r-- | src/mongo/bson/bsonobj.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h index 12374110747..ecdf8ef7b24 100644 --- a/src/mongo/bson/bsonobj.h +++ b/src/mongo/bson/bsonobj.h @@ -763,6 +763,25 @@ public: _theend = end - 1; } + /* + * Advance '_pos' by currentElement.size(). The element passed in must be equivalent to the + * current element '_pos' is at. + */ + void advance(const BSONElement& currentElement) { + dassert(BSONElement(_pos).size() == currentElement.size()); + _pos += currentElement.size(); + } + + /** + * Return true if the current element is equal to 'otherElement'. + * Do *not* use with moreWithEOO() as the function will return false if the current element and + * 'otherElement' are EOO. + */ + bool currentElementBinaryEqual(const BSONElement& otherElement) { + auto sz = otherElement.size(); + return sz <= (_theend - _pos) && memcmp(otherElement.rawdata(), _pos, sz) == 0; + } + /** @return true if more elements exist to be enumerated. */ bool more() const { return _pos < _theend; |