diff options
author | Dan Larkin-York <dan.larkin-york@mongodb.com> | 2021-11-02 14:34:08 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-11-02 15:31:52 +0000 |
commit | a1cb263e951d6a56332e2c8e074330669b80d9a9 (patch) | |
tree | af04e942129f37fdb17337bef8a2c2ff9ec59e46 | |
parent | 6ac6669487dae1a14780c94c8831fee00aaaed79 (diff) | |
download | mongo-a1cb263e951d6a56332e2c8e074330669b80d9a9.tar.gz |
SERVER-61124 Remove BSONElement::compare
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 102 | ||||
-rw-r--r-- | src/mongo/bson/bsonelement.h | 11 |
2 files changed, 0 insertions, 113 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index 82e2da9f87a..d93f928861c 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -482,96 +482,6 @@ int BSONElement::woCompare(const BSONElement& elem, return compareElements(*this, elem, rules, comparator); } -template <typename Comparator> -bool BSONElement::compare(const BSONElement& other, - Comparator comp, - ComparisonRulesSet rules, - const StringData::ComparatorInterface* stringComp) const { - if (type() != other.type()) - return comp(canonicalType(), other.canonicalType()); - if (rules & ComparisonRules::kConsiderFieldName) - return comp(fieldNameStringData(), other.fieldNameStringData()); - switch (other.type()) { - case BSONType::EOO: - case BSONType::Undefined: - case BSONType::jstNULL: - case BSONType::MaxKey: - case BSONType::MinKey: - return comp(canonicalType(), other.canonicalType()); - case BSONType::Bool: - return comp(*value(), *other.value()); - case BSONType::bsonTimestamp: - return comp(timestamp(), other.timestamp()); - case BSONType::Date: - return comp(Date(), other.Date()); - case BSONType::NumberInt: - return comp(_numberInt(), other._numberInt()); - case BSONType::NumberLong: - return comp(_numberLong(), other._numberLong()); - case BSONType::NumberDouble: - return comp(_numberDouble(), other._numberDouble()); - case BSONType::NumberDecimal: - return comp(_numberDecimal(), other._numberDecimal()); - case BSONType::jstOID: - return comp(memcmp(value(), other.value(), OID::kOIDSize), 0); - case BSONType::Code: - return comp(compareElementStringValues(*this, other), 0); - case BSONType::Symbol: - case BSONType::String: - return comp(stringComp ? stringComp->compare(valueStringData(), other.valueStringData()) - : compareElementStringValues(*this, other), - 0); - case BSONType::Object: - case BSONType::Array: - return comp( - embeddedObject().woCompare(other.embeddedObject(), - BSONObj(), - rules | BSONElement::ComparisonRules::kConsiderFieldName, - stringComp), - 0); - case BSONType::DBRef: { - int size = valuesize(); - int diff = size - other.valuesize(); - if (diff != 0) { - diff = memcmp(value(), other.value(), size); - } - return comp(diff, 0); - } - case BSONType::BinData: { - int size = objsize(); - int diff = size - other.objsize(); - if (diff != 0) { - diff = memcmp(value() + 4, other.value() + 4, size + 1); - } - return comp(diff, 0); - } - case BSONType::RegEx: { - int diff = strcmp(regex(), other.regex()); - if (diff != 0) { - diff = strcmp(regexFlags(), other.regexFlags()); - } - return comp(diff, 0); - } - case BSONType::CodeWScope: { - int diff = - StringData(codeWScopeCode(), codeWScopeCodeLen() - 1) - .compare(StringData(other.codeWScopeCode(), other.codeWScopeCodeLen() - 1)); - - // Consider field names when comparing scope objects. - if (diff != 0) { - diff = codeWScopeObject().woCompare( - other.codeWScopeObject(), - BSONObj(), - rules | BSONElement::ComparisonRules::kConsiderFieldName); - } - - return comp(diff, 0); - } - } - - MONGO_UNREACHABLE; -} - bool BSONElement::binaryEqual(const BSONElement& rhs) const { const int elemSize = size(); @@ -1082,16 +992,4 @@ struct BSONElementCodeWithScopeType { } bsonElementCodeWithScopeType; #endif // defined(_MSC_VER) && defined(_DEBUG) -template bool BSONElement::compare<std::less<>>( - const BSONElement& other, - std::less<> comp, - ComparisonRulesSet rules, - const StringData::ComparatorInterface* stringComp) const; - -template bool BSONElement::compare<std::greater<>>( - const BSONElement& other, - std::greater<> comp, - ComparisonRulesSet rules, - const StringData::ComparatorInterface* stringComp) const; - } // namespace mongo diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h index e519152202b..11a8ad6994a 100644 --- a/src/mongo/bson/bsonelement.h +++ b/src/mongo/bson/bsonelement.h @@ -624,17 +624,6 @@ public: ComparisonRulesSet rules = ComparisonRules::kConsiderFieldName, const StringData::ComparatorInterface* comparator = nullptr) const; - /** - * Returns a boolean for how, using the rules specified by 'rules' and the given - * comparison functions 'comp' and 'stringComp', this BSONElement compares with 'other'. - * Returns the result of BSONObj::woCompare if this object is an Array, Object, or CodeWScope. - */ - template <typename Comparator> - bool compare(const BSONElement& other, - Comparator comp, - ComparisonRulesSet rules = ComparisonRules::kConsiderFieldName, - const StringData::ComparatorInterface* stringComp = nullptr) const; - DeferredComparison operator<(const BSONElement& other) const { return DeferredComparison(DeferredComparison::Type::kLT, *this, other); } |