summaryrefslogtreecommitdiff
path: root/src/mongo/db/matcher/expression_leaf.cpp
diff options
context:
space:
mode:
authorTess Avitabile <tess.avitabile@mongodb.com>2017-08-01 15:32:03 -0400
committerTess Avitabile <tess.avitabile@mongodb.com>2017-08-09 10:43:42 -0400
commit50a1afafc816097ed57804ff7033dffd85dbe160 (patch)
treed9d54f202d8033391d74f4a2828a8d26123c3f07 /src/mongo/db/matcher/expression_leaf.cpp
parent2de7b036fd98ba618d4a9cf4cbe1cf8e81132d48 (diff)
downloadmongo-50a1afafc816097ed57804ff7033dffd85dbe160.tar.gz
SERVER-30189 Reduce calls to allocator for large $in expressions
Diffstat (limited to 'src/mongo/db/matcher/expression_leaf.cpp')
-rw-r--r--src/mongo/db/matcher/expression_leaf.cpp36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/mongo/db/matcher/expression_leaf.cpp b/src/mongo/db/matcher/expression_leaf.cpp
index a07c8ada9c5..4a0a4598927 100644
--- a/src/mongo/db/matcher/expression_leaf.cpp
+++ b/src/mongo/db/matcher/expression_leaf.cpp
@@ -593,29 +593,31 @@ bool InMatchExpression::equivalent(const MatchExpression* other) const {
void InMatchExpression::_doSetCollator(const CollatorInterface* collator) {
_collator = collator;
+ _eltCmp = BSONElementComparator(BSONElementComparator::FieldNamesMode::kIgnore, _collator);
// We need to re-compute '_equalitySet', since our set comparator has changed.
- BSONElementSet equalitiesWithNewComparator(
- _originalEqualityVector.begin(), _originalEqualityVector.end(), collator);
- _equalitySet = std::move(equalitiesWithNewComparator);
+ _equalitySet = _eltCmp.makeBSONEltFlatSet(_originalEqualityVector);
}
-Status InMatchExpression::addEquality(const BSONElement& elt) {
- if (elt.type() == BSONType::RegEx) {
- return Status(ErrorCodes::BadValue, "InMatchExpression equality cannot be a regex");
- }
- if (elt.type() == BSONType::Undefined) {
- return Status(ErrorCodes::BadValue, "InMatchExpression equality cannot be undefined");
- }
+Status InMatchExpression::setEqualities(std::vector<BSONElement> equalities) {
+ for (auto&& equality : equalities) {
+ if (equality.type() == BSONType::RegEx) {
+ return Status(ErrorCodes::BadValue, "InMatchExpression equality cannot be a regex");
+ }
+ if (equality.type() == BSONType::Undefined) {
+ return Status(ErrorCodes::BadValue, "InMatchExpression equality cannot be undefined");
+ }
- if (elt.type() == BSONType::jstNULL) {
- _hasNull = true;
- }
- if (elt.type() == BSONType::Array && elt.Obj().isEmpty()) {
- _hasEmptyArray = true;
+ if (equality.type() == BSONType::jstNULL) {
+ _hasNull = true;
+ } else if (equality.type() == BSONType::Array && equality.Obj().isEmpty()) {
+ _hasEmptyArray = true;
+ }
}
- _equalitySet.insert(elt);
- _originalEqualityVector.push_back(elt);
+ _originalEqualityVector = std::move(equalities);
+
+ _equalitySet = _eltCmp.makeBSONEltFlatSet(_originalEqualityVector);
+
return Status::OK();
}