diff options
author | David Storch <david.storch@10gen.com> | 2016-12-02 13:48:23 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-12-06 12:58:40 -0500 |
commit | 6f1824c8ff3b211f72e706de32b9637750cccf1e (patch) | |
tree | 0a4b2712bad469ace0ccef39b3496fa68ddf8bba /src/mongo/bson/bsonelement.cpp | |
parent | 6bee18129c27a82ebcbd316c7900afb04c6f69dc (diff) | |
download | mongo-6f1824c8ff3b211f72e706de32b9637750cccf1e.tar.gz |
SERVER-27197 fix BSONType::Code comparison to not use collator
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index 5131d5943ed..4417821f816 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -336,6 +336,19 @@ const StringMap<BSONObj::MatchType> queryOperatorMap{ {"bitsAnyClear", BSONObj::opBITS_ANY_CLEAR}, }; +// Compares two string elements using a simple binary compare. +int compareElementStringValues(const BSONElement& leftStr, const BSONElement& rightStr) { + // we use memcmp as we allow zeros in UTF8 strings + int lsz = leftStr.valuestrsize(); + int rsz = rightStr.valuestrsize(); + int common = std::min(lsz, rsz); + int res = memcmp(leftStr.valuestr(), rightStr.valuestr(), common); + if (res) + return res; + // longer std::string is the greater one + return lsz - rsz; +} + } // namespace int BSONElement::getGtLtOp(int def) const { @@ -943,20 +956,13 @@ int compareElementValues(const BSONElement& l, case jstOID: return memcmp(l.value(), r.value(), OID::kOIDSize); case Code: + return compareElementStringValues(l, r); case Symbol: case String: { if (comparator) { return comparator->compare(l.valueStringData(), r.valueStringData()); } else { - // we use memcmp as we allow zeros in UTF8 strings - int lsz = l.valuestrsize(); - int rsz = r.valuestrsize(); - int common = std::min(lsz, rsz); - int res = memcmp(l.valuestr(), r.valuestr(), common); - if (res) - return res; - // longer std::string is the greater one - return lsz - rsz; + return compareElementStringValues(l, r); } } case Object: |