diff options
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 19 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document.cpp | 10 |
2 files changed, 15 insertions, 14 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index 454a938a17f..77f5b7eb4ad 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -399,18 +399,17 @@ std::vector<BSONElement> BSONElement::Array() const { int BSONElement::woCompare(const BSONElement& e, bool considerFieldName, const StringData::ComparatorInterface* comparator) const { - int lt = (int)canonicalType(); - int rt = (int)e.canonicalType(); - int x = lt - rt; - if (x != 0 && (!isNumber() || !e.isNumber())) - return x; + if (type() != e.type()) { + int lt = (int)canonicalType(); + int rt = (int)e.canonicalType(); + if (int diff = lt - rt) + return diff; + } if (considerFieldName) { - x = strcmp(fieldName(), e.fieldName()); - if (x != 0) - return x; + if (int diff = strcmp(fieldName(), e.fieldName())) + return diff; } - x = compareElementValues(*this, e, comparator); - return x; + return compareElementValues(*this, e, comparator); } bool BSONElement::binaryEqual(const BSONElement& rhs) const { diff --git a/src/mongo/db/pipeline/document.cpp b/src/mongo/db/pipeline/document.cpp index e12b781ba5b..835ae1bc716 100644 --- a/src/mongo/db/pipeline/document.cpp +++ b/src/mongo/db/pipeline/document.cpp @@ -412,10 +412,12 @@ int Document::compare(const Document& rL, // For compatibility with BSONObj::woCompare() consider the canonical type of values // before considerting their names. - const int rCType = canonicalizeBSONType(rField.val.getType()); - const int lCType = canonicalizeBSONType(lField.val.getType()); - if (lCType != rCType) - return lCType < rCType ? -1 : 1; + if (lField.val.getType() != rField.val.getType()) { + const int rCType = canonicalizeBSONType(rField.val.getType()); + const int lCType = canonicalizeBSONType(lField.val.getType()); + if (lCType != rCType) + return lCType < rCType ? -1 : 1; + } const int nameCmp = lField.nameSD().compare(rField.nameSD()); if (nameCmp) |