diff options
author | Mathias Stearn <mathias@10gen.com> | 2017-06-29 11:54:45 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2017-07-03 19:07:13 -0400 |
commit | 477d732d98bd12fe34f45a582746e5d40f2636e5 (patch) | |
tree | d56c71d3b57eafcfc4b20febdb5c2fc965960ebf /src/mongo | |
parent | 5b83e73d2ec0165b15fd2e47f300b076d279f0c3 (diff) | |
download | mongo-477d732d98bd12fe34f45a582746e5d40f2636e5.tar.gz |
SERVER-29925 Only canonicalize bson types if they differ
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) |