summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hatch <david.hatch@mongodb.com>2016-07-21 13:27:49 -0400
committerDavid Hatch <david.hatch@mongodb.com>2016-07-22 16:21:19 -0400
commit4e1dacf63d435c91b8ae33c2982d13b3ca87a6d9 (patch)
tree99d70764b310e66df4e9e9d441f96fd1d8c218e0
parentf7c13e7396803e56ea46fe2d4418dbcf59b9eb57 (diff)
downloadmongo-4e1dacf63d435c91b8ae33c2982d13b3ca87a6d9.tar.gz
SERVER-24873 Remove StringData::ComparatorInterface default argument.
-rw-r--r--src/mongo/bson/mutable/algorithm.h37
-rw-r--r--src/mongo/bson/mutable/const_element-inl.h27
-rw-r--r--src/mongo/bson/mutable/const_element.h25
-rw-r--r--src/mongo/bson/mutable/document-inl.h12
-rw-r--r--src/mongo/bson/mutable/document.cpp22
-rw-r--r--src/mongo/bson/mutable/document.h11
-rw-r--r--src/mongo/bson/mutable/element.h12
-rw-r--r--src/mongo/bson/mutable/mutable_bson_algo_test.cpp10
-rw-r--r--src/mongo/bson/mutable/mutable_bson_test.cpp58
-rw-r--r--src/mongo/bson/mutable/mutable_bson_test_utils.cpp16
-rw-r--r--src/mongo/db/exec/update.cpp2
-rw-r--r--src/mongo/db/ops/modifier_add_to_set.cpp4
-rw-r--r--src/mongo/db/ops/modifier_add_to_set_test.cpp4
-rw-r--r--src/mongo/db/ops/modifier_compare.cpp2
-rw-r--r--src/mongo/db/ops/modifier_object_replace.cpp2
-rw-r--r--src/mongo/db/ops/modifier_pull.cpp2
-rw-r--r--src/mongo/db/ops/modifier_pull_all.cpp2
-rw-r--r--src/mongo/db/ops/modifier_push_sorter.h2
-rw-r--r--src/mongo/db/ops/path_support_test.cpp32
19 files changed, 136 insertions, 146 deletions
diff --git a/src/mongo/bson/mutable/algorithm.h b/src/mongo/bson/mutable/algorithm.h
index de1134e0162..768469deff4 100644
--- a/src/mongo/bson/mutable/algorithm.h
+++ b/src/mongo/bson/mutable/algorithm.h
@@ -167,51 +167,48 @@ void deduplicateChildren(Element parent, EqualityComparator equal) {
class woLess {
// TODO: This should possibly derive from std::binary_function.
public:
- woLess(bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr)
- : _considerFieldName(considerFieldName), _comp(comparator) {}
+ woLess(const StringData::ComparatorInterface* comparator, bool considerFieldName = true)
+ : _comp(comparator), _considerFieldName(considerFieldName) {}
inline bool operator()(const ConstElement& left, const ConstElement& right) const {
- return left.compareWithElement(right, _considerFieldName, _comp) < 0;
+ return left.compareWithElement(right, _comp, _considerFieldName) < 0;
}
private:
- const bool _considerFieldName;
const StringData::ComparatorInterface* _comp = nullptr;
+ const bool _considerFieldName;
};
/** A greater-than ordering for Elements that compares based on woCompare */
class woGreater {
// TODO: This should possibly derive from std::binary_function.
public:
- woGreater(bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr)
- : _considerFieldName(considerFieldName), _comp(comparator) {}
+ woGreater(const StringData::ComparatorInterface* comparator, bool considerFieldName = true)
+ : _comp(comparator), _considerFieldName(considerFieldName) {}
inline bool operator()(const ConstElement& left, const ConstElement& right) const {
- return left.compareWithElement(right, _considerFieldName, _comp) > 0;
+ return left.compareWithElement(right, _comp, _considerFieldName) > 0;
}
private:
- const bool _considerFieldName;
const StringData::ComparatorInterface* _comp = nullptr;
+ const bool _considerFieldName;
};
/** An equality predicate for elements that compares based on woCompare */
class woEqual {
// TODO: This should possibly derive from std::binary_function.
public:
- woEqual(bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr)
- : _considerFieldName(considerFieldName), _comp(comparator) {}
+ woEqual(const StringData::ComparatorInterface* comparator, bool considerFieldName = true)
+ : _comp(comparator), _considerFieldName(considerFieldName) {}
inline bool operator()(const ConstElement& left, const ConstElement& right) const {
- return left.compareWithElement(right, _considerFieldName, _comp) == 0;
+ return left.compareWithElement(right, _comp, _considerFieldName) == 0;
}
private:
- const bool _considerFieldName;
const StringData::ComparatorInterface* _comp = nullptr;
+ const bool _considerFieldName;
};
/** An equality predicate for elements that compares based on woCompare */
@@ -219,18 +216,18 @@ class woEqualTo {
// TODO: This should possibly derive from std::binary_function.
public:
woEqualTo(const ConstElement& value,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr)
- : _value(value), _considerFieldName(considerFieldName), _comp(comparator) {}
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true)
+ : _value(value), _comp(comparator), _considerFieldName(considerFieldName) {}
inline bool operator()(const ConstElement& elt) const {
- return _value.compareWithElement(elt, _considerFieldName, _comp) == 0;
+ return _value.compareWithElement(elt, _comp, _considerFieldName) == 0;
}
private:
const ConstElement _value;
- const bool _considerFieldName;
const StringData::ComparatorInterface* _comp = nullptr;
+ const bool _considerFieldName;
};
// NOTE: Originally, these truly were algorithms, in that they executed the loop over a
diff --git a/src/mongo/bson/mutable/const_element-inl.h b/src/mongo/bson/mutable/const_element-inl.h
index 2d00ec0b797..84a140e0117 100644
--- a/src/mongo/bson/mutable/const_element-inl.h
+++ b/src/mongo/bson/mutable/const_element-inl.h
@@ -164,25 +164,22 @@ inline SafeNum ConstElement::getValueSafeNum() const {
return _basis.getValueSafeNum();
}
-inline int ConstElement::compareWithElement(
- const ConstElement& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
- return _basis.compareWithElement(other, considerFieldName, comparator);
+inline int ConstElement::compareWithElement(const ConstElement& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return _basis.compareWithElement(other, comparator, considerFieldName);
}
-inline int ConstElement::compareWithBSONElement(
- const BSONElement& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
- return _basis.compareWithBSONElement(other, considerFieldName, comparator);
+inline int ConstElement::compareWithBSONElement(const BSONElement& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return _basis.compareWithBSONElement(other, comparator, considerFieldName);
}
-inline int ConstElement::compareWithBSONObj(
- const BSONObj& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
- return _basis.compareWithBSONObj(other, considerFieldName, comparator);
+inline int ConstElement::compareWithBSONObj(const BSONObj& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return _basis.compareWithBSONObj(other, comparator, considerFieldName);
}
inline void ConstElement::writeTo(BSONObjBuilder* builder) const {
diff --git a/src/mongo/bson/mutable/const_element.h b/src/mongo/bson/mutable/const_element.h
index d9798309204..c570f398095 100644
--- a/src/mongo/bson/mutable/const_element.h
+++ b/src/mongo/bson/mutable/const_element.h
@@ -88,20 +88,17 @@ public:
inline bool isValueMaxKey() const;
inline SafeNum getValueSafeNum() const;
- inline int compareWithElement(
- const ConstElement& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
-
- inline int compareWithBSONElement(
- const BSONElement& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
-
- inline int compareWithBSONObj(
- const BSONObj& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
+ inline int compareWithElement(const ConstElement& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
+
+ inline int compareWithBSONElement(const BSONElement& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
+
+ inline int compareWithBSONObj(const BSONObj& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
inline void writeTo(BSONObjBuilder* builder) const;
inline void writeArrayTo(BSONArrayBuilder* builder) const;
diff --git a/src/mongo/bson/mutable/document-inl.h b/src/mongo/bson/mutable/document-inl.h
index 6942283ceb1..e6f9b60ec64 100644
--- a/src/mongo/bson/mutable/document-inl.h
+++ b/src/mongo/bson/mutable/document-inl.h
@@ -31,18 +31,18 @@ namespace mongo {
namespace mutablebson {
inline int Document::compareWith(const Document& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
// We cheat and use Element::compareWithElement since we know that 'other' is a
// Document and has a 'hidden' fieldname that is always indentical across all Document
// instances.
- return root().compareWithElement(other.root(), considerFieldName, comparator);
+ return root().compareWithElement(other.root(), comparator, considerFieldName);
}
inline int Document::compareWithBSONObj(const BSONObj& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
- return root().compareWithBSONObj(other, considerFieldName, comparator);
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
+ return root().compareWithBSONObj(other, comparator, considerFieldName);
}
inline void Document::writeTo(BSONObjBuilder* builder) const {
diff --git a/src/mongo/bson/mutable/document.cpp b/src/mongo/bson/mutable/document.cpp
index 10817ab0050..ddf1f83281d 100644
--- a/src/mongo/bson/mutable/document.cpp
+++ b/src/mongo/bson/mutable/document.cpp
@@ -1487,8 +1487,8 @@ SafeNum Element::getValueSafeNum() const {
}
int Element::compareWithElement(const ConstElement& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
invariant(ok());
invariant(other.ok());
@@ -1511,14 +1511,14 @@ int Element::compareWithElement(const ConstElement& other,
// in all cases.
if (impl.hasValue(thisRep))
return -other.compareWithBSONElement(
- impl.getSerializedElement(thisRep), considerFieldName, comparator);
+ impl.getSerializedElement(thisRep), comparator, considerFieldName);
const Document::Impl& oimpl = other.getDocument().getImpl();
const ElementRep& otherRep = oimpl.getElementRep(other.getIdx());
if (oimpl.hasValue(otherRep))
return compareWithBSONElement(
- oimpl.getSerializedElement(otherRep), considerFieldName, comparator);
+ oimpl.getSerializedElement(otherRep), comparator, considerFieldName);
// Leaf elements should always have a value, so we should only be dealing with Objects
// or Arrays here.
@@ -1560,7 +1560,7 @@ int Element::compareWithElement(const ConstElement& other,
return 1;
const int result =
- thisIter.compareWithElement(otherIter, considerChildFieldNames, comparator);
+ thisIter.compareWithElement(otherIter, comparator, considerChildFieldNames);
if (result != 0)
return result;
@@ -1570,8 +1570,8 @@ int Element::compareWithElement(const ConstElement& other,
}
int Element::compareWithBSONElement(const BSONElement& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
invariant(ok());
const Document::Impl& impl = getDocument().getImpl();
@@ -1607,12 +1607,12 @@ int Element::compareWithBSONElement(const BSONElement& other,
const bool considerChildFieldNames =
(impl.getType(thisRep) != mongo::Array) && (other.type() != mongo::Array);
- return compareWithBSONObj(other.Obj(), considerChildFieldNames, comparator);
+ return compareWithBSONObj(other.Obj(), comparator, considerChildFieldNames);
}
int Element::compareWithBSONObj(const BSONObj& other,
- bool considerFieldName,
- const StringData::ComparatorInterface* comparator) const {
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName) const {
invariant(ok());
const Document::Impl& impl = getDocument().getImpl();
@@ -1634,7 +1634,7 @@ int Element::compareWithBSONObj(const BSONObj& other,
if (otherVal.eoo())
return 1;
- const int result = thisIter.compareWithBSONElement(otherVal, considerFieldName, comparator);
+ const int result = thisIter.compareWithBSONElement(otherVal, comparator, considerFieldName);
if (result != 0)
return result;
diff --git a/src/mongo/bson/mutable/document.h b/src/mongo/bson/mutable/document.h
index 60cbaab3cde..443cee1bebc 100644
--- a/src/mongo/bson/mutable/document.h
+++ b/src/mongo/bson/mutable/document.h
@@ -278,14 +278,13 @@ public:
/** Compare this Document to 'other' with the semantics of BSONObj::woCompare. */
inline int compareWith(const Document& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
/** Compare this Document to 'other' with the semantics of BSONObj::woCompare. */
- inline int compareWithBSONObj(
- const BSONObj& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
+ inline int compareWithBSONObj(const BSONObj& other,
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
//
diff --git a/src/mongo/bson/mutable/element.h b/src/mongo/bson/mutable/element.h
index 690894b285d..270d990e1ac 100644
--- a/src/mongo/bson/mutable/element.h
+++ b/src/mongo/bson/mutable/element.h
@@ -351,8 +351,8 @@ public:
* Returns 1 if this > other according to BSONElement::woCompare
*/
int compareWithElement(const ConstElement& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
/** Compare this Element with BSONElement 'other'. You should not call this on the root
* Element of the Document because the root Element does not have a field name. Use
@@ -363,8 +363,8 @@ public:
* Returns 1 if this > other according to BSONElement::woCompare
*/
int compareWithBSONElement(const BSONElement& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
/** Compare this Element, which must be an Object or an Array, with 'other'.
*
@@ -373,8 +373,8 @@ public:
* Returns 1 if this object > other according to BSONElement::woCompare
*/
int compareWithBSONObj(const BSONObj& other,
- bool considerFieldName = true,
- const StringData::ComparatorInterface* comparator = nullptr) const;
+ const StringData::ComparatorInterface* comparator,
+ bool considerFieldName = true) const;
//
diff --git a/src/mongo/bson/mutable/mutable_bson_algo_test.cpp b/src/mongo/bson/mutable/mutable_bson_algo_test.cpp
index ade055a543f..727a10689f7 100644
--- a/src/mongo/bson/mutable/mutable_bson_algo_test.cpp
+++ b/src/mongo/bson/mutable/mutable_bson_algo_test.cpp
@@ -311,7 +311,7 @@ TEST_F(CountTest, CountSiblingsMany) {
TEST(DeduplicateTest, ManyDuplicates) {
Document doc(mongo::fromjson("{ x : [ 1, 2, 2, 3, 3, 3, 4, 4, 4 ] }"));
- deduplicateChildren(doc.root().leftChild(), woEqual(false));
+ deduplicateChildren(doc.root().leftChild(), woEqual(nullptr, false));
ASSERT_TRUE(checkDoc(doc, mongo::fromjson("{x : [ 1, 2, 3, 4 ]}")));
}
@@ -336,7 +336,7 @@ TEST(WoLessTest, CollationAware) {
Document less(mongo::fromjson("{ x: 'cbc' }"));
Document greater(mongo::fromjson("{ x: 'abd' }"));
- woLess comp(true, &collator);
+ woLess comp(&collator, true);
ASSERT_TRUE(comp(less.root(), greater.root()));
ASSERT_FALSE(comp(greater.root(), less.root()));
}
@@ -346,7 +346,7 @@ TEST(WoGreaterTest, CollationAware) {
Document less(mongo::fromjson("{ x: 'cbc' }"));
Document greater(mongo::fromjson("{ x: 'abd' }"));
- woGreater comp(true, &collator);
+ woGreater comp(&collator, true);
ASSERT_TRUE(comp(greater.root(), less.root()));
ASSERT_FALSE(comp(less.root(), greater.root()));
}
@@ -356,7 +356,7 @@ TEST(WoEqualTest, CollationAware) {
Document docA(mongo::fromjson("{ x: 'not' }"));
Document docB(mongo::fromjson("{ x: 'equal' }"));
- woEqual comp(true, &collator);
+ woEqual comp(&collator, true);
ASSERT_TRUE(comp(docA.root(), docB.root()));
ASSERT_TRUE(comp(docB.root(), docA.root()));
}
@@ -366,7 +366,7 @@ TEST(WoEqualToTest, CollationAware) {
Document docA(mongo::fromjson("{ x: 'not' }"));
Document docB(mongo::fromjson("{ x: 'equal' }"));
- woEqualTo comp(docA.root(), true, &collator);
+ woEqualTo comp(docA.root(), &collator, true);
ASSERT_TRUE(comp(docB.root()));
}
diff --git a/src/mongo/bson/mutable/mutable_bson_test.cpp b/src/mongo/bson/mutable/mutable_bson_test.cpp
index 3c865cea71a..24629617926 100644
--- a/src/mongo/bson/mutable/mutable_bson_test.cpp
+++ b/src/mongo/bson/mutable/mutable_bson_test.cpp
@@ -3186,10 +3186,10 @@ TEST(DocumentComparison, SimpleComparison) {
mongo::fromjson("{ a : 'a', b : ['b', 'b', 'b'], c : { one : 1.0 } }");
const mmb::Document doc1(obj.getOwned());
- ASSERT_EQUALS(0, doc1.compareWithBSONObj(obj));
+ ASSERT_EQUALS(0, doc1.compareWithBSONObj(obj, nullptr));
const mmb::Document doc2(obj.getOwned());
- ASSERT_EQUALS(0, doc1.compareWith(doc2));
- ASSERT_EQUALS(0, doc2.compareWith(doc1));
+ ASSERT_EQUALS(0, doc1.compareWith(doc2, nullptr));
+ ASSERT_EQUALS(0, doc2.compareWith(doc1, nullptr));
}
TEST(DocumentComparison, SimpleComparisonWithDeserializedElements) {
@@ -3207,10 +3207,10 @@ TEST(DocumentComparison, SimpleComparisonWithDeserializedElements) {
ASSERT_OK(b0.remove());
ASSERT_OK(b.pushBack(b0));
// Ensure that it compares correctly against the source object.
- ASSERT_EQUALS(0, doc1.compareWithBSONObj(obj));
+ ASSERT_EQUALS(0, doc1.compareWithBSONObj(obj, nullptr));
// Ensure that it compares correctly against a pristine document.
- ASSERT_EQUALS(0, doc1.compareWith(doc1Copy));
- ASSERT_EQUALS(0, doc1Copy.compareWith(doc1));
+ ASSERT_EQUALS(0, doc1.compareWith(doc1Copy, nullptr));
+ ASSERT_EQUALS(0, doc1Copy.compareWith(doc1, nullptr));
// Perform an operation on 'c' that doesn't change the serialized value, but
// deserializeds the node.
@@ -3223,14 +3223,14 @@ TEST(DocumentComparison, SimpleComparisonWithDeserializedElements) {
ASSERT_OK(c1.remove());
ASSERT_OK(c.pushBack(c1));
// Ensure that it compares correctly against the source object
- ASSERT_EQUALS(0, doc2.compareWithBSONObj(obj));
+ ASSERT_EQUALS(0, doc2.compareWithBSONObj(obj, nullptr));
// Ensure that it compares correctly against a pristine document.
- ASSERT_EQUALS(0, doc2.compareWith(doc2Copy));
- ASSERT_EQUALS(0, doc2Copy.compareWith(doc2));
+ ASSERT_EQUALS(0, doc2.compareWith(doc2Copy, nullptr));
+ ASSERT_EQUALS(0, doc2Copy.compareWith(doc2, nullptr));
// Ensure that the two deserialized documents compare with each other correctly.
- ASSERT_EQUALS(0, doc1.compareWith(doc2));
- ASSERT_EQUALS(0, doc2.compareWith(doc1));
+ ASSERT_EQUALS(0, doc1.compareWith(doc2, nullptr));
+ ASSERT_EQUALS(0, doc2.compareWith(doc1, nullptr));
}
TEST(DocumentComparison, DocumentCompareWithRespectsCollation) {
@@ -3239,8 +3239,8 @@ TEST(DocumentComparison, DocumentCompareWithRespectsCollation) {
const mmb::Document doc2(mongo::fromjson("{a: 'bar'}"));
// Pass true to indicate that we should compare field names. The two documents should be unequal
// without the collator, but equal when using the "always equal" collator.
- ASSERT_NE(0, doc1.compareWith(doc2, true));
- ASSERT_EQ(0, doc1.compareWith(doc2, true, &collator));
+ ASSERT_NE(0, doc1.compareWith(doc2, nullptr, true));
+ ASSERT_EQ(0, doc1.compareWith(doc2, &collator, true));
}
TEST(DocumentComparison, DocumentCompareWithBSONObjRespectsCollation) {
@@ -3249,8 +3249,8 @@ TEST(DocumentComparison, DocumentCompareWithBSONObjRespectsCollation) {
const mongo::BSONObj doc2 = mongo::fromjson("{a: 'bar'}");
// Pass true to indicate that we should compare field names. The two documents should be unequal
// without the collator, but equal when using the "always equal" collator.
- ASSERT_NE(0, doc1.compareWithBSONObj(doc2, true));
- ASSERT_EQ(0, doc1.compareWithBSONObj(doc2, true, &collator));
+ ASSERT_NE(0, doc1.compareWithBSONObj(doc2, nullptr, true));
+ ASSERT_EQ(0, doc1.compareWithBSONObj(doc2, &collator, true));
}
TEST(DocumentComparison, ElementCompareWithElementRespectsCollator) {
@@ -3261,8 +3261,8 @@ TEST(DocumentComparison, ElementCompareWithElementRespectsCollator) {
const mmb::ConstElement element2 = doc2.root().leftChild();
// Pass true to indicate that we should compare field names. The two documents should be unequal
// without the collator, but equal when using the "always equal" collator.
- ASSERT_NE(0, element1.compareWithElement(element2, true));
- ASSERT_EQ(0, element1.compareWithElement(element2, true, &collator));
+ ASSERT_NE(0, element1.compareWithElement(element2, nullptr, true));
+ ASSERT_EQ(0, element1.compareWithElement(element2, &collator, true));
}
TEST(DocumentComparison, ElementCompareWithBSONElementRespectsCollator) {
@@ -3273,8 +3273,8 @@ TEST(DocumentComparison, ElementCompareWithBSONElementRespectsCollator) {
const mongo::BSONElement element2 = doc2["a"];
// Pass true to indicate that we should compare field names. The two documents should be unequal
// without the collator, but equal when using the "always equal" collator.
- ASSERT_NE(0, element1.compareWithBSONElement(element2, true));
- ASSERT_EQ(0, element1.compareWithBSONElement(element2, true, &collator));
+ ASSERT_NE(0, element1.compareWithBSONElement(element2, nullptr, true));
+ ASSERT_EQ(0, element1.compareWithBSONElement(element2, &collator, true));
}
TEST(DocumentComparison, ElementCompareWithBSONObjRespectsCollator) {
@@ -3284,8 +3284,8 @@ TEST(DocumentComparison, ElementCompareWithBSONObjRespectsCollator) {
const mmb::ConstElement element1 = doc1.root().leftChild();
// Pass true to indicate that we should compare field names. The two documents should be unequal
// without the collator, but equal when using the "always equal" collator.
- ASSERT_NE(0, element1.compareWithBSONObj(doc2, true));
- ASSERT_EQ(0, element1.compareWithBSONObj(doc2, true, &collator));
+ ASSERT_NE(0, element1.compareWithBSONObj(doc2, nullptr, true));
+ ASSERT_EQ(0, element1.compareWithBSONObj(doc2, &collator, true));
}
TEST(DocumentComparison, DocumentCompareWithRespectsCollationRecursively) {
@@ -3294,8 +3294,8 @@ TEST(DocumentComparison, DocumentCompareWithRespectsCollationRecursively) {
const mmb::Document doc2(mongo::fromjson("{a: [{b: 'notFoo'}, {b: 'notBar'}]}"));
// Pass true to indicate that we should compare field names. The two documents should be unequal
// without the collator, but equal when using the "always equal" collator.
- ASSERT_NE(0, doc1.compareWith(doc2, true));
- ASSERT_EQ(0, doc1.compareWith(doc2, true, &collator));
+ ASSERT_NE(0, doc1.compareWith(doc2, nullptr, true));
+ ASSERT_EQ(0, doc1.compareWith(doc2, &collator, true));
}
TEST(DocumentComparison, DocumentCompareWithRespectsCollationWithDeserializedElement) {
@@ -3304,8 +3304,8 @@ TEST(DocumentComparison, DocumentCompareWithRespectsCollationWithDeserializedEle
mmb::Document doc2(mongo::fromjson("{a: ['bar', 'bar']}"));
// With the always equal collator, the documents should start out comparing equal.
- ASSERT_EQ(0, doc1.compareWith(doc2, true, &collator));
- ASSERT_EQ(0, doc2.compareWith(doc1, true, &collator));
+ ASSERT_EQ(0, doc1.compareWith(doc2, &collator, true));
+ ASSERT_EQ(0, doc2.compareWith(doc1, &collator, true));
// They should still be equal after causing deserialization of one of the leaf elements of
// 'doc1'.
@@ -3316,8 +3316,8 @@ TEST(DocumentComparison, DocumentCompareWithRespectsCollationWithDeserializedEle
ASSERT_TRUE(elementA0.ok());
ASSERT_OK(elementA0.remove());
ASSERT_OK(elementA.pushBack(elementA0));
- ASSERT_EQ(0, doc1.compareWith(doc2, true, &collator));
- ASSERT_EQ(0, doc2.compareWith(doc1, true, &collator));
+ ASSERT_EQ(0, doc1.compareWith(doc2, &collator, true));
+ ASSERT_EQ(0, doc2.compareWith(doc1, &collator, true));
}
// And they should remain equal after doing the same to 'doc2'.
@@ -3328,8 +3328,8 @@ TEST(DocumentComparison, DocumentCompareWithRespectsCollationWithDeserializedEle
ASSERT_TRUE(elementA0.ok());
ASSERT_OK(elementA0.remove());
ASSERT_OK(elementA.pushBack(elementA0));
- ASSERT_EQ(0, doc1.compareWith(doc2, true, &collator));
- ASSERT_EQ(0, doc2.compareWith(doc1, true, &collator));
+ ASSERT_EQ(0, doc1.compareWith(doc2, &collator, true));
+ ASSERT_EQ(0, doc2.compareWith(doc1, &collator, true));
}
}
diff --git a/src/mongo/bson/mutable/mutable_bson_test_utils.cpp b/src/mongo/bson/mutable/mutable_bson_test_utils.cpp
index 3102c48eb54..5ad657d66b9 100644
--- a/src/mongo/bson/mutable/mutable_bson_test_utils.cpp
+++ b/src/mongo/bson/mutable/mutable_bson_test_utils.cpp
@@ -142,7 +142,7 @@ bool checkDocNoOrderingImpl(ConstElement lhs, ConstElement rhs) {
} else {
// This is some leaf type. We've already checked or ignored field names, so
// don't recheck it here.
- return lhs.compareWithElement(rhs, false) == 0;
+ return lhs.compareWithElement(rhs, nullptr, false) == 0;
}
}
@@ -158,30 +158,30 @@ bool checkDoc(const Document& lhs, const BSONObj& rhs) {
const int primaryResult = fromLhs.woCompare(rhs);
// Validate primary result via other comparison paths.
- const int secondaryResult = lhs.compareWithBSONObj(rhs);
+ const int secondaryResult = lhs.compareWithBSONObj(rhs, nullptr);
assertSameSign(primaryResult, secondaryResult);
// Check that mutables serialized result matches against its origin.
- ASSERT_EQUALS(0, lhs.compareWithBSONObj(fromLhs));
+ ASSERT_EQUALS(0, lhs.compareWithBSONObj(fromLhs, nullptr));
return (primaryResult == 0);
}
bool checkDoc(const Document& lhs, const Document& rhs) {
- const int primaryResult = lhs.compareWith(rhs);
+ const int primaryResult = lhs.compareWith(rhs, nullptr);
const BSONObj fromLhs = lhs.getObject();
const BSONObj fromRhs = rhs.getObject();
- const int result_d_o = lhs.compareWithBSONObj(fromRhs);
- const int result_o_d = rhs.compareWithBSONObj(fromLhs);
+ const int result_d_o = lhs.compareWithBSONObj(fromRhs, nullptr);
+ const int result_o_d = rhs.compareWithBSONObj(fromLhs, nullptr);
assertSameSign(primaryResult, result_d_o);
assertOppositeSign(primaryResult, result_o_d);
- ASSERT_EQUALS(0, lhs.compareWithBSONObj(fromLhs));
- ASSERT_EQUALS(0, rhs.compareWithBSONObj(fromRhs));
+ ASSERT_EQUALS(0, lhs.compareWithBSONObj(fromLhs, nullptr));
+ ASSERT_EQUALS(0, rhs.compareWithBSONObj(fromRhs, nullptr));
return (primaryResult == 0);
}
diff --git a/src/mongo/db/exec/update.cpp b/src/mongo/db/exec/update.cpp
index a8f58613a5b..72c84ac6f7e 100644
--- a/src/mongo/db/exec/update.cpp
+++ b/src/mongo/db/exec/update.cpp
@@ -375,7 +375,7 @@ inline Status validate(const BSONObj& original,
}
// If we have both (old and new), compare them. If we just have new we are good
- if (oldElem.ok() && newElem.compareWithBSONElement(oldElem, false) != 0) {
+ if (oldElem.ok() && newElem.compareWithBSONElement(oldElem, nullptr, false) != 0) {
return Status(ErrorCodes::ImmutableField,
mongoutils::str::stream()
<< "After applying the update to the document {"
diff --git a/src/mongo/db/ops/modifier_add_to_set.cpp b/src/mongo/db/ops/modifier_add_to_set.cpp
index 7ef613a2bcd..a565800d749 100644
--- a/src/mongo/db/ops/modifier_add_to_set.cpp
+++ b/src/mongo/db/ops/modifier_add_to_set.cpp
@@ -205,7 +205,7 @@ void ModifierAddToSet::setCollator(const CollatorInterface* collator) {
invariant(!_collator);
_collator = collator;
// Deduplicate _val (must be performed after collator is set to final value.)
- deduplicate(_val, mb::woLess(false, _collator), mb::woEqual(false, _collator));
+ deduplicate(_val, mb::woLess(_collator, false), mb::woEqual(_collator, false));
}
Status ModifierAddToSet::prepare(mb::Element root, StringData matchedField, ExecInfo* execInfo) {
@@ -275,7 +275,7 @@ Status ModifierAddToSet::prepare(mb::Element root, StringData matchedField, Exec
mb::Element eachIter = _val.leftChild();
while (eachIter.ok()) {
mb::Element where = mb::findElement(_preparedState->elemFound.leftChild(),
- mb::woEqualTo(eachIter, false, _collator));
+ mb::woEqualTo(eachIter, _collator, false));
if (!where.ok()) {
// The element was not found. Record the element from $each as one to be added.
_preparedState->elementsToAdd.push_back(eachIter);
diff --git a/src/mongo/db/ops/modifier_add_to_set_test.cpp b/src/mongo/db/ops/modifier_add_to_set_test.cpp
index 060cefcda26..235a65239e6 100644
--- a/src/mongo/db/ops/modifier_add_to_set_test.cpp
+++ b/src/mongo/db/ops/modifier_add_to_set_test.cpp
@@ -402,8 +402,8 @@ TEST(Deduplication, DeduplicationRespectsCollation) {
ASSERT_FALSE(execInfo.noOp);
ASSERT_OK(mod.apply());
- ASSERT(doc.compareWithBSONObj(fromjson("{ a : ['bar', 'FOO'] }"), false) == 0 ||
- doc.compareWithBSONObj(fromjson("{ a: ['bar', 'foo'] }"), false) == 0);
+ ASSERT(doc.compareWithBSONObj(fromjson("{ a : ['bar', 'FOO'] }"), nullptr, false) == 0 ||
+ doc.compareWithBSONObj(fromjson("{ a: ['bar', 'foo'] }"), nullptr, false) == 0);
}
TEST(Deduplication, ExistingDuplicatesArePreservedWithRespectToCollation) {
diff --git a/src/mongo/db/ops/modifier_compare.cpp b/src/mongo/db/ops/modifier_compare.cpp
index 1db3461b303..4e366f90ee2 100644
--- a/src/mongo/db/ops/modifier_compare.cpp
+++ b/src/mongo/db/ops/modifier_compare.cpp
@@ -130,7 +130,7 @@ Status ModifierCompare::prepare(mutablebson::Element root,
execInfo->noOp = false;
} else {
const int compareVal =
- _preparedState->elemFound.compareWithBSONElement(_val, false, _collator);
+ _preparedState->elemFound.compareWithBSONElement(_val, _collator, false);
execInfo->noOp = (compareVal == 0) ||
((_mode == ModifierCompare::MAX) ? (compareVal > 0) : (compareVal < 0));
}
diff --git a/src/mongo/db/ops/modifier_object_replace.cpp b/src/mongo/db/ops/modifier_object_replace.cpp
index 0cecd5a0d1e..b33b1d76615 100644
--- a/src/mongo/db/ops/modifier_object_replace.cpp
+++ b/src/mongo/db/ops/modifier_object_replace.cpp
@@ -148,7 +148,7 @@ Status ModifierObjectReplace::apply() const {
// Do not duplicate _id field
if (srcIdElement.ok()) {
- if (srcIdElement.compareWithBSONElement(dstIdElement, true) != 0) {
+ if (srcIdElement.compareWithBSONElement(dstIdElement, nullptr, true) != 0) {
return Status(ErrorCodes::ImmutableField,
str::stream() << "The _id field cannot be changed from {"
<< srcIdElement.toString()
diff --git a/src/mongo/db/ops/modifier_pull.cpp b/src/mongo/db/ops/modifier_pull.cpp
index 82cdbb7204b..9a7b8608555 100644
--- a/src/mongo/db/ops/modifier_pull.cpp
+++ b/src/mongo/db/ops/modifier_pull.cpp
@@ -272,7 +272,7 @@ bool ModifierPull::isMatch(mutablebson::ConstElement element) {
dassert(element.hasValue());
if (!_matchExpr)
- return (element.compareWithBSONElement(_exprElt, false, _collator) == 0);
+ return (element.compareWithBSONElement(_exprElt, _collator, false) == 0);
if (_matcherOnPrimitive) {
// TODO: This is kinda slow.
diff --git a/src/mongo/db/ops/modifier_pull_all.cpp b/src/mongo/db/ops/modifier_pull_all.cpp
index 07d5e081266..2d57bea1cb5 100644
--- a/src/mongo/db/ops/modifier_pull_all.cpp
+++ b/src/mongo/db/ops/modifier_pull_all.cpp
@@ -74,7 +74,7 @@ struct mutableElementEqualsBSONElement : std::unary_function<BSONElement, bool>
const CollatorInterface* collator)
: _what(elem), _collator(collator) {}
bool operator()(const BSONElement& elem) const {
- return _what.compareWithBSONElement(elem, false, _collator) == 0;
+ return _what.compareWithBSONElement(elem, _collator, false) == 0;
}
const mutablebson::Element& _what;
const CollatorInterface* _collator = nullptr;
diff --git a/src/mongo/db/ops/modifier_push_sorter.h b/src/mongo/db/ops/modifier_push_sorter.h
index 346f754d9bb..6e2ef53cfcd 100644
--- a/src/mongo/db/ops/modifier_push_sorter.h
+++ b/src/mongo/db/ops/modifier_push_sorter.h
@@ -47,7 +47,7 @@ struct PatternElementCmp {
bool operator()(const mutablebson::Element& lhs, const mutablebson::Element& rhs) const {
namespace dps = ::mongo::dotted_path_support;
if (useWholeValue) {
- const int comparedValue = lhs.compareWithElement(rhs, false, collator);
+ const int comparedValue = lhs.compareWithElement(rhs, collator, false);
const bool reversed = (sortPattern.firstElement().number() < 0);
diff --git a/src/mongo/db/ops/path_support_test.cpp b/src/mongo/db/ops/path_support_test.cpp
index f1de975850f..ac74c387668 100644
--- a/src/mongo/db/ops/path_support_test.cpp
+++ b/src/mongo/db/ops/path_support_test.cpp
@@ -151,7 +151,7 @@ TEST_F(SimpleDoc, SimplePath) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"], nullptr), 0);
}
TEST_F(SimpleDoc, LongerPath) {
@@ -163,7 +163,7 @@ TEST_F(SimpleDoc, LongerPath) {
ASSERT_EQUALS(status, ErrorCodes::PathNotViable);
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"], nullptr), 0);
}
TEST_F(SimpleDoc, NotCommonPrefix) {
@@ -239,7 +239,7 @@ TEST_F(NestedDoc, SimplePath) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"], nullptr), 0);
}
TEST_F(NestedDoc, ShorterPath) {
@@ -249,7 +249,7 @@ TEST_F(NestedDoc, ShorterPath) {
Element elemFound = root();
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_EQUALS(idxFound, 1U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"], nullptr), 0);
}
TEST_F(NestedDoc, ExactPath) {
@@ -260,7 +260,7 @@ TEST_F(NestedDoc, ExactPath) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 2U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]["c"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]["c"], nullptr), 0);
}
TEST_F(NestedDoc, LongerPath) {
@@ -273,7 +273,7 @@ TEST_F(NestedDoc, LongerPath) {
ASSERT_EQUALS(status.code(), ErrorCodes::PathNotViable);
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 2U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]["c"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]["c"], nullptr), 0);
}
TEST_F(NestedDoc, NewFieldNested) {
@@ -283,7 +283,7 @@ TEST_F(NestedDoc, NewFieldNested) {
Element elemFound = root();
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_EQUALS(idxFound, 1U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"], nullptr), 0);
// From this point on, handles the creation of the '.d' part that wasn't found.
Element newElem = doc().makeElementInt("d", 1);
@@ -301,7 +301,7 @@ TEST_F(NestedDoc, NotStartingFromRoot) {
Element elemFound = root();
ASSERT_OK(findLongestPrefix(field(), root()["a"], &idxFound, &elemFound));
ASSERT_EQUALS(idxFound, 1U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]["c"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]["b"]["c"], nullptr), 0);
}
class ArrayDoc : public mongo::unittest::Test {
@@ -353,7 +353,7 @@ TEST_F(ArrayDoc, PathOnEmptyArray) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["a"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["a"], nullptr), 0);
}
TEST_F(ArrayDoc, PathOnPopulatedArray) {
@@ -364,7 +364,7 @@ TEST_F(ArrayDoc, PathOnPopulatedArray) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 1U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"][0]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"][0], nullptr), 0);
}
TEST_F(ArrayDoc, MixedArrayAndObjectPath) {
@@ -375,7 +375,7 @@ TEST_F(ArrayDoc, MixedArrayAndObjectPath) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 2U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"][0]["c"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"][0]["c"], nullptr), 0);
}
TEST_F(ArrayDoc, ExtendingExistingObject) {
@@ -386,7 +386,7 @@ TEST_F(ArrayDoc, ExtendingExistingObject) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 1U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"][0]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"][0], nullptr), 0);
// From this point on, handles the creation of the '.0.d' part that wasn't found.
Element newElem = doc().makeElementInt("d", 1);
@@ -405,7 +405,7 @@ TEST_F(ArrayDoc, NewObjectInsideArray) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"], nullptr), 0);
// From this point on, handles the creation of the '.1.c' part that wasn't found.
Element newElem = doc().makeElementInt("c", 2);
@@ -424,7 +424,7 @@ TEST_F(ArrayDoc, NewNestedObjectInsideArray) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"], nullptr), 0);
// From this point on, handles the creation of the '.1.c.d' part that wasn't found.
Element newElem = doc().makeElementInt("d", 2);
@@ -443,7 +443,7 @@ TEST_F(ArrayDoc, ArrayPaddingNecessary) {
ASSERT_OK(findLongestPrefix(field(), root(), &idxFound, &elemFound));
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"], nullptr), 0);
// From this point on, handles the creation of the '.5' part that wasn't found.
Element newElem = doc().makeElementInt("", 1);
@@ -512,7 +512,7 @@ TEST_F(ArrayDoc, NonNumericPathInArray) {
ASSERT_EQUALS(status.code(), ErrorCodes::PathNotViable);
ASSERT_TRUE(elemFound.ok());
ASSERT_EQUALS(idxFound, 0U);
- ASSERT_EQUALS(elemFound.compareWithElement(root()["b"]), 0);
+ ASSERT_EQUALS(elemFound.compareWithElement(root()["b"], nullptr), 0);
}
//