summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.cpp
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2016-05-04 19:16:43 -0400
committerAndrew Morrow <acm@mongodb.com>2016-05-05 16:15:25 -0400
commita7e243500cbf11d1e153f55b551c86713ddf2a9b (patch)
tree7dea0a249a42350afe2d6b94c52c180feaa8763b /src/mongo/bson/bsonelement.cpp
parentd5b670a01622ff5b9cd8dc1a988321022948182b (diff)
downloadmongo-a7e243500cbf11d1e153f55b551c86713ddf2a9b.tar.gz
SERVER-16801 Require strict equality for $set no-op checks
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r--src/mongo/bson/bsonelement.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index 0de4ce56a33..9c64c21c973 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -396,6 +396,31 @@ int BSONElement::woCompare(const BSONElement& e,
return x;
}
+bool BSONElement::binaryEqual(const BSONElement& rhs) const {
+ const int elemSize = size();
+
+ if (elemSize != rhs.size()) {
+ return false;
+ }
+
+ return (elemSize == 0) || (memcmp(data, rhs.rawdata(), elemSize) == 0);
+}
+
+bool BSONElement::binaryEqualValues(const BSONElement& rhs) const {
+ // The binaryEqual method above implicitly compares the type, but we need to do so explicitly
+ // here. It doesn't make sense to consider to BSONElement objects as binaryEqual if they have
+ // the same bit pattern but different types (consider an integer and a double).
+ if (type() != rhs.type())
+ return false;
+
+ const int valueSize = valuesize();
+ if (valueSize != rhs.valuesize()) {
+ return false;
+ }
+
+ return (valueSize == 0) || (memcmp(value(), rhs.value(), valueSize) == 0);
+}
+
BSONObj BSONElement::embeddedObjectUserCheck() const {
if (MONGO_likely(isABSONObj()))
return BSONObj(value());