summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.cpp
diff options
context:
space:
mode:
authorMatt Kneiser <matt.kneiser@mongodb.com>2022-01-25 18:19:19 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-26 18:39:11 +0000
commitc2ae46fba2647747b05fb95c84c9c0b4a5bffd5f (patch)
tree6b703daf4b9bfb96e3b137a82b950d04ee52a3d2 /src/mongo/bson/bsonelement.cpp
parent3de3fdef4f8fd55285d032ffc59be2bdf8fb96aa (diff)
downloadmongo-c2ae46fba2647747b05fb95c84c9c0b4a5bffd5f.tar.gz
SERVER-62980 Revert simplification of compareElementStringValues for perf
Diffstat (limited to 'src/mongo/bson/bsonelement.cpp')
-rw-r--r--src/mongo/bson/bsonelement.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp
index c6cf2437be2..430b259699b 100644
--- a/src/mongo/bson/bsonelement.cpp
+++ b/src/mongo/bson/bsonelement.cpp
@@ -271,7 +271,15 @@ namespace {
// Compares two string elements using a simple binary compare.
int compareElementStringValues(const BSONElement& leftStr, const BSONElement& rightStr) {
- return leftStr.valueStringData().compare(rightStr.valueStringData());
+ // 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.value() + 4), (rightStr.value() + 4), common);
+ if (res)
+ return res;
+ // longer std::string is the greater one
+ return lsz - rsz;
}
} // namespace