summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2016-06-30 17:30:41 -0400
committerDavid Storch <david.storch@10gen.com>2016-08-19 09:27:56 -0400
commit9aef6602683af7842e04c025c47d652b3897c541 (patch)
treee5c4e70714c4a4e38fc450cdd65628ad58b70107 /src/mongo
parente404756a317fbd531306805cf77e723b9c3fc218 (diff)
downloadmongo-9aef6602683af7842e04c025c47d652b3897c541.tar.gz
SERVER-24508 delete BSONObj::equal()
Instead, use comparator.evaluate(obj1 == obj2), where comparator is of type BSONObj::ComparatorInterface.
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/bson/bsonobj.cpp15
-rw-r--r--src/mongo/bson/bsonobj.h2
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp4
-rw-r--r--src/mongo/db/range_deleter_test.cpp28
-rw-r--r--src/mongo/db/s/metadata_loader_test.cpp2
-rw-r--r--src/mongo/db/storage/mmap_v1/btree/key.cpp3
-rw-r--r--src/mongo/dbtests/jsobjtests.cpp9
-rw-r--r--src/mongo/scripting/bson_template_evaluator_test.cpp8
8 files changed, 27 insertions, 44 deletions
diff --git a/src/mongo/bson/bsonobj.cpp b/src/mongo/bson/bsonobj.cpp
index 992e2dd0a89..ca2e0991403 100644
--- a/src/mongo/bson/bsonobj.cpp
+++ b/src/mongo/bson/bsonobj.cpp
@@ -46,21 +46,6 @@ namespace mongo {
using namespace std;
/* BSONObj ------------------------------------------------------------*/
-// deep (full) equality
-bool BSONObj::equal(const BSONObj& rhs) const {
- BSONObjIterator i(*this);
- BSONObjIterator j(rhs);
- BSONElement l, r;
- do {
- // so far, equal...
- l = i.next();
- r = j.next();
- if (l.eoo())
- return r.eoo();
- } while (l == r);
- return false;
-}
-
void BSONObj::_assertInvalid() const {
StringBuilder ss;
int os = objsize();
diff --git a/src/mongo/bson/bsonobj.h b/src/mongo/bson/bsonobj.h
index 726a5f43be9..cfd35c2513f 100644
--- a/src/mongo/bson/bsonobj.h
+++ b/src/mongo/bson/bsonobj.h
@@ -474,8 +474,6 @@ public:
return DeferredComparison(DeferredComparison::Type::kNE, *this, other);
}
- bool equal(const BSONObj& r) const;
-
/**
* Functor compatible with std::hash for std::unordered_{map,set}
* Warning: The hash function is subject to change. Do not use in cases where hashes need
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index 4690b5daa46..cfffe585778 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -665,7 +665,7 @@ Status IndexCatalog::_doesSpecConflictWithExisting(OperationContext* txn,
if (desc) {
// index already exists with same name
- if (desc->keyPattern().equal(key) &&
+ if (SimpleBSONObjComparator::kInstance.evaluate(desc->keyPattern() == key) &&
SimpleBSONObjComparator::kInstance.evaluate(
desc->infoObj().getObjectField("collation") != collation)) {
// key patterns are equal but collations differ.
@@ -680,7 +680,7 @@ Status IndexCatalog::_doesSpecConflictWithExisting(OperationContext* txn,
<< spec);
}
- if (!desc->keyPattern().equal(key) ||
+ if (SimpleBSONObjComparator::kInstance.evaluate(desc->keyPattern() != key) ||
SimpleBSONObjComparator::kInstance.evaluate(
desc->infoObj().getObjectField("collation") != collation)) {
return Status(ErrorCodes::IndexKeySpecsConflict,
diff --git a/src/mongo/db/range_deleter_test.cpp b/src/mongo/db/range_deleter_test.cpp
index 34c3a4b5739..0a625507b61 100644
--- a/src/mongo/db/range_deleter_test.cpp
+++ b/src/mongo/db/range_deleter_test.cpp
@@ -121,8 +121,8 @@ TEST(QueuedDelete, ShouldWaitCursor) {
const DeletedRange deletedChunk(env->getLastDelete());
ASSERT_EQUALS(ns, deletedChunk.ns);
- ASSERT_TRUE(deletedChunk.min.equal(BSON("x" << 0)));
- ASSERT_TRUE(deletedChunk.max.equal(BSON("x" << 10)));
+ ASSERT_BSONOBJ_EQ(deletedChunk.min, BSON("x" << 0));
+ ASSERT_BSONOBJ_EQ(deletedChunk.max, BSON("x" << 10));
deleter.stopWorkers();
}
@@ -209,9 +209,9 @@ TEST(ImmediateDelete, ShouldWaitCursor) {
const DeletedRange deletedChunk(env->getLastDelete());
ASSERT_EQUALS(ns, deletedChunk.ns);
- ASSERT_TRUE(deletedChunk.min.equal(BSON("x" << 0)));
- ASSERT_TRUE(deletedChunk.max.equal(BSON("x" << 10)));
- ASSERT_TRUE(deletedChunk.shardKeyPattern.equal(BSON("x" << 1)));
+ ASSERT_BSONOBJ_EQ(deletedChunk.min, BSON("x" << 0));
+ ASSERT_BSONOBJ_EQ(deletedChunk.max, BSON("x" << 10));
+ ASSERT_BSONOBJ_EQ(deletedChunk.shardKeyPattern, BSON("x" << 1));
}
// Should terminate when stop is requested.
@@ -328,9 +328,9 @@ TEST(MixedDeletes, MultipleDeletes) {
DeletedRange deleted1(env->getLastDelete());
ASSERT_EQUALS(ns, deleted1.ns);
- ASSERT_TRUE(deleted1.min.equal(BSON("x" << 10)));
- ASSERT_TRUE(deleted1.max.equal(BSON("x" << 20)));
- ASSERT_TRUE(deleted1.shardKeyPattern.equal(BSON("x" << 1)));
+ ASSERT_BSONOBJ_EQ(deleted1.min, BSON("x" << 10));
+ ASSERT_BSONOBJ_EQ(deleted1.max, BSON("x" << 20));
+ ASSERT_BSONOBJ_EQ(deleted1.shardKeyPattern, BSON("x" << 1));
// Let the second delete proceed.
env->resumeOneDelete();
@@ -342,9 +342,9 @@ TEST(MixedDeletes, MultipleDeletes) {
// cursors open for blockedNS.
ASSERT_EQUALS(ns, deleted2.ns);
- ASSERT_TRUE(deleted2.min.equal(BSON("x" << 30)));
- ASSERT_TRUE(deleted2.max.equal(BSON("x" << 40)));
- ASSERT_TRUE(deleted2.shardKeyPattern.equal(BSON("x" << 1)));
+ ASSERT_BSONOBJ_EQ(deleted2.min, BSON("x" << 30));
+ ASSERT_BSONOBJ_EQ(deleted2.max, BSON("x" << 40));
+ ASSERT_BSONOBJ_EQ(deleted2.shardKeyPattern, BSON("x" << 1));
env->removeCursorId(blockedNS, 345);
// Let the last delete proceed.
@@ -354,9 +354,9 @@ TEST(MixedDeletes, MultipleDeletes) {
DeletedRange deleted3(env->getLastDelete());
ASSERT_EQUALS(blockedNS, deleted3.ns);
- ASSERT_TRUE(deleted3.min.equal(BSON("x" << 20)));
- ASSERT_TRUE(deleted3.max.equal(BSON("x" << 30)));
- ASSERT_TRUE(deleted3.shardKeyPattern.equal(BSON("x" << 1)));
+ ASSERT_BSONOBJ_EQ(deleted3.min, BSON("x" << 20));
+ ASSERT_BSONOBJ_EQ(deleted3.max, BSON("x" << 30));
+ ASSERT_BSONOBJ_EQ(deleted3.shardKeyPattern, BSON("x" << 1));
deleter.stopWorkers();
}
diff --git a/src/mongo/db/s/metadata_loader_test.cpp b/src/mongo/db/s/metadata_loader_test.cpp
index aef88ecc380..5aaaf11d624 100644
--- a/src/mongo/db/s/metadata_loader_test.cpp
+++ b/src/mongo/db/s/metadata_loader_test.cpp
@@ -357,7 +357,7 @@ TEST_F(MetadataLoaderFixture, SingleChunkGetShardKey) {
NULL, /* no old metadata */
&metadata);
ChunkType chunkInfo;
- ASSERT_TRUE(metadata.getKeyPattern().equal(BSON("a" << 1)));
+ ASSERT_BSONOBJ_EQ(metadata.getKeyPattern(), BSON("a" << 1));
});
expectFindOnConfigSendCollectionDefault();
diff --git a/src/mongo/db/storage/mmap_v1/btree/key.cpp b/src/mongo/db/storage/mmap_v1/btree/key.cpp
index 93bd939559e..27b17cb6879 100644
--- a/src/mongo/db/storage/mmap_v1/btree/key.cpp
+++ b/src/mongo/db/storage/mmap_v1/btree/key.cpp
@@ -34,6 +34,7 @@
#include "mongo/base/data_type_endian.h"
#include "mongo/base/data_view.h"
+#include "mongo/bson/simple_bsonobj_comparator.h"
#include "mongo/bson/util/builder.h"
#include "mongo/util/log.h"
#include "mongo/util/startup_test.h"
@@ -649,7 +650,7 @@ bool KeyV1::woEqual(const KeyV1& right) const {
const unsigned char* r = right._keyData;
if ((*l | *r) == IsBSON) {
- return toBson().equal(right.toBson());
+ return SimpleBSONObjComparator::kInstance.evaluate(toBson() == right.toBson());
}
while (1) {
diff --git a/src/mongo/dbtests/jsobjtests.cpp b/src/mongo/dbtests/jsobjtests.cpp
index d2182b557fd..34dff8ada09 100644
--- a/src/mongo/dbtests/jsobjtests.cpp
+++ b/src/mongo/dbtests/jsobjtests.cpp
@@ -174,9 +174,8 @@ void keyTest(const BSONObj& o, bool mustBeCompact = false) {
ASSERT(!k.isCompactFormat() || k.dataSize() < o.objsize());
{
- // check BSONObj::equal. this part not a KeyV1 test.
int res = o.woCompare(last);
- ASSERT((res == 0) == o.equal(last));
+ ASSERT((res == 0) == SimpleBSONObjComparator::kInstance.evaluate(o == last));
}
if (kLast) {
@@ -802,7 +801,7 @@ public:
// check (non)equality
BSONObj a = BSONObjBuilder().appendBinData("", 8, (BinDataType)1, "abcdefgh").obj();
BSONObj b = BSONObjBuilder().appendBinData("", 8, (BinDataType)1, "abcdefgj").obj();
- ASSERT(!a.equal(b));
+ ASSERT_BSONOBJ_NE(a, b);
int res_ab = a.woCompare(b);
ASSERT(res_ab != 0);
keyTest(a, true);
@@ -811,11 +810,11 @@ public:
// check subtypes do not equal
BSONObj c = BSONObjBuilder().appendBinData("", 8, (BinDataType)4, "abcdefgh").obj();
BSONObj d = BSONObjBuilder().appendBinData("", 8, (BinDataType)0x81, "abcdefgh").obj();
- ASSERT(!a.equal(c));
+ ASSERT_BSONOBJ_NE(a, c);
int res_ac = a.woCompare(c);
ASSERT(res_ac != 0);
keyTest(c, true);
- ASSERT(!a.equal(d));
+ ASSERT_BSONOBJ_NE(a, d);
int res_ad = a.woCompare(d);
ASSERT(res_ad != 0);
keyTest(d, true);
diff --git a/src/mongo/scripting/bson_template_evaluator_test.cpp b/src/mongo/scripting/bson_template_evaluator_test.cpp
index 51e573fc7e0..3ae6cca9797 100644
--- a/src/mongo/scripting/bson_template_evaluator_test.cpp
+++ b/src/mongo/scripting/bson_template_evaluator_test.cpp
@@ -532,7 +532,7 @@ TEST(BSONTemplateEvaluatorTest, CONCAT) {
ASSERT_EQUALS(obj2.nFields(), 1);
BSONObj expectedObj = BSON("concatField"
<< "hello world");
- ASSERT_EQUALS(obj2.equal(expectedObj), true);
+ ASSERT_BSONOBJ_EQ(obj2, expectedObj);
// Test success when some arguments to #CONCAT are integers
BSONObjBuilder builder3;
@@ -543,7 +543,7 @@ TEST(BSONTemplateEvaluatorTest, CONCAT) {
ASSERT_EQUALS(obj3.nFields(), 1);
expectedObj = BSON("concatField"
<< "F1racing");
- ASSERT_EQUALS(obj3.equal(expectedObj), true);
+ ASSERT_BSONOBJ_EQ(obj3, expectedObj);
// Test success with #CONCAT as first element and last element
BSONObjBuilder builder4;
@@ -562,7 +562,7 @@ TEST(BSONTemplateEvaluatorTest, CONCAT) {
<< 1
<< "concatField2"
<< "hello world");
- ASSERT_EQUALS(obj4.equal(expectedObj), true);
+ ASSERT_BSONOBJ_EQ(obj4, expectedObj);
// Test success when one of the arguments to #CONCAT is an array
BSONObjBuilder builder5;
@@ -573,7 +573,7 @@ TEST(BSONTemplateEvaluatorTest, CONCAT) {
ASSERT_EQUALS(obj5.nFields(), 1);
expectedObj = BSON("concatField"
<< "hello[ 1, 10 ]world");
- ASSERT_EQUALS(obj5.equal(expectedObj), true);
+ ASSERT_BSONOBJ_EQ(obj5, expectedObj);
}
TEST(BSONTemplateEvaluatorTest, OID) {