diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2020-04-21 00:38:10 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-05-02 02:12:49 +0000 |
commit | f002800003e9ddf21d8511a0835be0526bc9b614 (patch) | |
tree | 1ea5a2f57f0715b1c6dda7bf9916cc19d0e210d8 /src/mongo | |
parent | 4d8bc5a24d08a7db945a000d569557fc1f04d539 (diff) | |
download | mongo-f002800003e9ddf21d8511a0835be0526bc9b614.tar.gz |
SERVER-41068 remove map_util.h
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/client/replica_set_monitor_manager.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/auth/authorization_manager_test.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/auth/authorization_session_test.cpp | 1 | ||||
-rw-r--r-- | src/mongo/db/auth/authz_manager_external_state_mock.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/background.cpp | 21 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_info.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/server_options_helpers.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/server_options_server_helpers.cpp | 1 | ||||
-rw-r--r-- | src/mongo/dbtests/mock/mock_replica_set.cpp | 4 | ||||
-rw-r--r-- | src/mongo/executor/connection_pool_stats.cpp | 1 | ||||
-rw-r--r-- | src/mongo/logger/ramlog.cpp | 14 | ||||
-rw-r--r-- | src/mongo/logger/rotatable_file_manager.cpp | 4 | ||||
-rw-r--r-- | src/mongo/logv2/ramlog.cpp | 15 | ||||
-rw-r--r-- | src/mongo/s/client/shard_registry.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/commands/cluster_is_master_cmd.cpp | 12 | ||||
-rw-r--r-- | src/mongo/scripting/bson_template_evaluator.cpp | 4 | ||||
-rw-r--r-- | src/mongo/util/map_util.h | 45 |
17 files changed, 42 insertions, 109 deletions
diff --git a/src/mongo/client/replica_set_monitor_manager.cpp b/src/mongo/client/replica_set_monitor_manager.cpp index 57274b71d14..bbf2a95ad9d 100644 --- a/src/mongo/client/replica_set_monitor_manager.cpp +++ b/src/mongo/client/replica_set_monitor_manager.cpp @@ -51,7 +51,6 @@ #include "mongo/logv2/log.h" #include "mongo/platform/mutex.h" #include "mongo/rpc/metadata/egress_metadata_hook_list.h" -#include "mongo/util/map_util.h" namespace mongo { diff --git a/src/mongo/db/auth/authorization_manager_test.cpp b/src/mongo/db/auth/authorization_manager_test.cpp index 1578db97b18..b0e24ccaa38 100644 --- a/src/mongo/db/auth/authorization_manager_test.cpp +++ b/src/mongo/db/auth/authorization_manager_test.cpp @@ -53,7 +53,6 @@ #include "mongo/transport/session.h" #include "mongo/transport/transport_layer_mock.h" #include "mongo/unittest/unittest.h" -#include "mongo/util/map_util.h" #define ASSERT_NULL(EXPR) ASSERT_FALSE(EXPR) #define ASSERT_NON_NULL(EXPR) ASSERT_TRUE(EXPR) diff --git a/src/mongo/db/auth/authorization_session_test.cpp b/src/mongo/db/auth/authorization_session_test.cpp index 049c9bb587b..81dff04b7f3 100644 --- a/src/mongo/db/auth/authorization_session_test.cpp +++ b/src/mongo/db/auth/authorization_session_test.cpp @@ -52,7 +52,6 @@ #include "mongo/transport/session.h" #include "mongo/transport/transport_layer_mock.h" #include "mongo/unittest/unittest.h" -#include "mongo/util/map_util.h" namespace mongo { namespace { diff --git a/src/mongo/db/auth/authz_manager_external_state_mock.cpp b/src/mongo/db/auth/authz_manager_external_state_mock.cpp index 2967e62ff0f..ff292b3ab86 100644 --- a/src/mongo/db/auth/authz_manager_external_state_mock.cpp +++ b/src/mongo/db/auth/authz_manager_external_state_mock.cpp @@ -46,7 +46,6 @@ #include "mongo/db/namespace_string.h" #include "mongo/db/operation_context_noop.h" #include "mongo/db/update/update_driver.h" -#include "mongo/util/map_util.h" #include "mongo/util/str.h" namespace mongo { @@ -274,7 +273,10 @@ Status AuthzManagerExternalStateMock::remove(OperationContext* opCtx, std::vector<BSONObj> AuthzManagerExternalStateMock::getCollectionContents( const NamespaceString& collectionName) { - return mapFindWithDefault(_documents, collectionName, std::vector<BSONObj>()); + auto iter = _documents.find(collectionName); + if (iter != _documents.end()) + return iter->second; + return {}; } Status AuthzManagerExternalStateMock::_findOneIter(OperationContext* opCtx, diff --git a/src/mongo/db/background.cpp b/src/mongo/db/background.cpp index 14da56c02ec..e77eff20cd5 100644 --- a/src/mongo/db/background.cpp +++ b/src/mongo/db/background.cpp @@ -39,7 +39,6 @@ #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/thread.h" #include "mongo/util/assert_util.h" -#include "mongo/util/map_util.h" #include "mongo/util/str.h" #include "mongo/util/string_map.h" @@ -123,22 +122,16 @@ void recordEndAndRemove(BgInfoMap& bgiMap, StringData key) { } void awaitNoBgOps(stdx::unique_lock<Latch>& lk, BgInfoMap* bgiMap, StringData key) { - std::shared_ptr<BgInfo> bgInfo = mapFindWithDefault(*bgiMap, key, std::shared_ptr<BgInfo>()); - if (!bgInfo) - return; - bgInfo->awaitNoBgOps(lk); + if (auto iter = bgiMap->find(key); iter != bgiMap->end()) + iter->second->awaitNoBgOps(lk); } } // namespace void BackgroundOperation::waitUntilAnIndexBuildFinishes(OperationContext* opCtx, StringData ns) { stdx::unique_lock<Latch> lk(m); - std::shared_ptr<BgInfo> bgInfo = mapFindWithDefault(nsInProg, ns, std::shared_ptr<BgInfo>()); - if (!bgInfo) { - // There are no index builds in progress on the collection, so no need to wait. - return; - } - bgInfo->waitForAnOpRemoval(lk, opCtx); + if (auto iter = nsInProg.find(ns); iter != nsInProg.end()) + iter->second->waitForAnOpRemoval(lk, opCtx); } bool BackgroundOperation::inProgForDb(StringData db) { @@ -148,10 +141,8 @@ bool BackgroundOperation::inProgForDb(StringData db) { int BackgroundOperation::numInProgForDb(StringData db) { stdx::lock_guard<Latch> lk(m); - std::shared_ptr<BgInfo> bgInfo = mapFindWithDefault(dbsInProg, db, std::shared_ptr<BgInfo>()); - if (!bgInfo) - return 0; - return bgInfo->getOpsInProgCount(); + auto iter = dbsInProg.find(db); + return iter == dbsInProg.end() ? 0 : iter->second->getOpsInProgCount(); } bool BackgroundOperation::inProgForNs(StringData ns) { diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index c6c98e4c992..f4be131dba5 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -65,7 +65,6 @@ #include "mongo/transport/ismaster_metrics.h" #include "mongo/util/decimal_counter.h" #include "mongo/util/fail_point.h" -#include "mongo/util/map_util.h" namespace mongo { @@ -501,11 +500,9 @@ public: result.append("readOnly", storageGlobalParams.readOnly); - const auto parameter = mapFindWithDefault(ServerParameterSet::getGlobal()->getMap(), - "automationServiceDescriptor", - static_cast<ServerParameter*>(nullptr)); - if (parameter) - parameter->append(opCtx, result, "automationServiceDescriptor"); + const auto& params = ServerParameterSet::getGlobal()->getMap(); + if (auto iter = params.find("automationServiceDescriptor"); iter != params.end()) + iter->second->append(opCtx, result, "automationServiceDescriptor"); if (opCtx->getClient()->session()) { MessageCompressorManager::forSession(opCtx->getClient()->session()) diff --git a/src/mongo/db/server_options_helpers.cpp b/src/mongo/db/server_options_helpers.cpp index c27eec4edd6..a0171882e4f 100644 --- a/src/mongo/db/server_options_helpers.cpp +++ b/src/mongo/db/server_options_helpers.cpp @@ -54,7 +54,6 @@ #include "mongo/transport/message_compressor_registry.h" #include "mongo/util/cmdline_utils/censor_cmdline.h" #include "mongo/util/fail_point.h" -#include "mongo/util/map_util.h" #include "mongo/util/net/sock.h" #include "mongo/util/net/socket_utils.h" #include "mongo/util/net/ssl_options.h" @@ -420,10 +419,9 @@ Status storeBaseOptions(const moe::Environment& params) { for (std::map<std::string, std::string>::iterator parametersIt = parameters.begin(); parametersIt != parameters.end(); parametersIt++) { - ServerParameter* parameter = - mapFindWithDefault(ServerParameterSet::getGlobal()->getMap(), - parametersIt->first, - static_cast<ServerParameter*>(nullptr)); + const auto& serverParams = ServerParameterSet::getGlobal()->getMap(); + auto iter = serverParams.find(parametersIt->first); + ServerParameter* parameter = (iter == serverParams.end()) ? nullptr : iter->second; if (nullptr == parameter) { StringBuilder sb; sb << "Illegal --setParameter parameter: \"" << parametersIt->first << "\""; diff --git a/src/mongo/db/server_options_server_helpers.cpp b/src/mongo/db/server_options_server_helpers.cpp index c4aaca42c0f..44d01d99f79 100644 --- a/src/mongo/db/server_options_server_helpers.cpp +++ b/src/mongo/db/server_options_server_helpers.cpp @@ -54,7 +54,6 @@ #include "mongo/transport/message_compressor_registry.h" #include "mongo/util/cmdline_utils/censor_cmdline.h" #include "mongo/util/fail_point.h" -#include "mongo/util/map_util.h" #include "mongo/util/net/sock.h" #include "mongo/util/net/socket_utils.h" #include "mongo/util/net/ssl_options.h" diff --git a/src/mongo/dbtests/mock/mock_replica_set.cpp b/src/mongo/dbtests/mock/mock_replica_set.cpp index b533ceb4099..12e288ab1a7 100644 --- a/src/mongo/dbtests/mock/mock_replica_set.cpp +++ b/src/mongo/dbtests/mock/mock_replica_set.cpp @@ -35,7 +35,6 @@ #include "mongo/dbtests/mock/mock_conn_registry.h" #include "mongo/dbtests/mock/mock_dbclient_connection.h" #include "mongo/util/invariant.h" -#include "mongo/util/map_util.h" #include <sstream> @@ -166,7 +165,8 @@ vector<string> MockReplicaSet::getSecondaries() const { } MockRemoteDBServer* MockReplicaSet::getNode(const string& hostAndPort) { - return mapFindWithDefault(_nodeMap, hostAndPort, static_cast<MockRemoteDBServer*>(nullptr)); + auto iter = _nodeMap.find(hostAndPort); + return iter == _nodeMap.end() ? nullptr : iter->second; } repl::ReplSetConfig MockReplicaSet::getReplConfig() const { diff --git a/src/mongo/executor/connection_pool_stats.cpp b/src/mongo/executor/connection_pool_stats.cpp index 31da4d38f96..c11aff401da 100644 --- a/src/mongo/executor/connection_pool_stats.cpp +++ b/src/mongo/executor/connection_pool_stats.cpp @@ -32,7 +32,6 @@ #include "mongo/executor/connection_pool_stats.h" #include "mongo/bson/bsonobjbuilder.h" -#include "mongo/util/map_util.h" namespace mongo { namespace executor { diff --git a/src/mongo/logger/ramlog.cpp b/src/mongo/logger/ramlog.cpp index 77dca9dd48c..938ab194608 100644 --- a/src/mongo/logger/ramlog.cpp +++ b/src/mongo/logger/ramlog.cpp @@ -34,7 +34,6 @@ #include "mongo/base/init.h" #include "mongo/base/status.h" #include "mongo/logger/message_event_utf8_encoder.h" -#include "mongo/util/map_util.h" #include "mongo/util/str.h" namespace mongo { @@ -179,19 +178,18 @@ RamLog* RamLog::get(const std::string& name) { _named = new RM(); } - RamLog* result = mapFindWithDefault(*_named, name, static_cast<RamLog*>(nullptr)); - if (!result) { - result = new RamLog(name); - (*_named)[name] = result; - } - return result; + auto [iter, isNew] = _named->try_emplace(name); + if (isNew) + iter->second = new RamLog(name); + return iter->second; } RamLog* RamLog::getIfExists(const std::string& name) { if (!_named) return nullptr; stdx::lock_guard<stdx::mutex> lk(*_namedLock); - return mapFindWithDefault(*_named, name, static_cast<RamLog*>(nullptr)); + auto iter = _named->find(name); + return iter == _named->end() ? nullptr : iter->second; } void RamLog::getNames(std::vector<string>& names) { diff --git a/src/mongo/logger/rotatable_file_manager.cpp b/src/mongo/logger/rotatable_file_manager.cpp index 4ba06af6f5c..ca5b1c3f745 100644 --- a/src/mongo/logger/rotatable_file_manager.cpp +++ b/src/mongo/logger/rotatable_file_manager.cpp @@ -32,7 +32,6 @@ #include "mongo/logger/rotatable_file_manager.h" #include "mongo/logger/rotatable_file_writer.h" -#include "mongo/util/map_util.h" namespace mongo { namespace logger { @@ -61,7 +60,8 @@ StatusWithRotatableFileWriter RotatableFileManager::openFile(const std::string& } RotatableFileWriter* RotatableFileManager::getFile(const std::string& name) { - return mapFindWithDefault(_writers, name, static_cast<RotatableFileWriter*>(nullptr)); + auto iter = _writers.find(name); + return iter == _writers.end() ? nullptr : iter->second; } RotatableFileManager::FileNameStatusPairVector RotatableFileManager::rotateAll( diff --git a/src/mongo/logv2/ramlog.cpp b/src/mongo/logv2/ramlog.cpp index ee04ff0e0be..eb2a01b72e1 100644 --- a/src/mongo/logv2/ramlog.cpp +++ b/src/mongo/logv2/ramlog.cpp @@ -33,7 +33,6 @@ #include "mongo/base/init.h" #include "mongo/base/status.h" -#include "mongo/util/map_util.h" #include "mongo/util/str.h" namespace mongo::logv2 { @@ -159,13 +158,10 @@ RamLog* RamLog::get(const std::string& name) { _named = new RM(); } - RamLog* result = mapFindWithDefault(*_named, name, static_cast<RamLog*>(NULL)); - if (!result) { - result = new RamLog(name); - (*_named)[name] = result; - } - - return result; + auto [iter, isNew] = _named->try_emplace(name); + if (isNew) + iter->second = new RamLog(name); + return iter->second; } RamLog* RamLog::getIfExists(const std::string& name) { @@ -173,7 +169,8 @@ RamLog* RamLog::getIfExists(const std::string& name) { return NULL; } stdx::lock_guard<stdx::mutex> lk(*_namedLock); - return mapFindWithDefault(*_named, name, static_cast<RamLog*>(NULL)); + auto iter = _named->find(name); + return iter == _named->end() ? nullptr : iter->second; } void RamLog::getNames(std::vector<string>& names) { diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp index 68c6a3aea73..61ee14708a1 100644 --- a/src/mongo/s/client/shard_registry.cpp +++ b/src/mongo/s/client/shard_registry.cpp @@ -59,7 +59,6 @@ #include "mongo/s/client/shard_factory.h" #include "mongo/s/grid.h" #include "mongo/util/concurrency/with_lock.h" -#include "mongo/util/map_util.h" #include "mongo/util/scopeguard.h" #include "mongo/util/str.h" @@ -537,7 +536,8 @@ shared_ptr<Shard> ShardRegistryData::_findByConnectionString( shared_ptr<Shard> ShardRegistryData::_findByHostAndPort(WithLock, const HostAndPort& hostAndPort) const { - return mapFindWithDefault(_hostLookup, hostAndPort); + auto i = _hostLookup.find(hostAndPort); + return (i != _hostLookup.end()) ? i->second : nullptr; } shared_ptr<Shard> ShardRegistryData::_findByShardId(WithLock, ShardId const& shardId) const { diff --git a/src/mongo/s/commands/cluster_is_master_cmd.cpp b/src/mongo/s/commands/cluster_is_master_cmd.cpp index d597b051468..0fb7eefe6b3 100644 --- a/src/mongo/s/commands/cluster_is_master_cmd.cpp +++ b/src/mongo/s/commands/cluster_is_master_cmd.cpp @@ -44,7 +44,6 @@ #include "mongo/rpc/topology_version_gen.h" #include "mongo/s/mongos_topology_coordinator.h" #include "mongo/transport/message_compressor_manager.h" -#include "mongo/util/map_util.h" #include "mongo/util/net/socket_utils.h" #include "mongo/util/version.h" @@ -170,11 +169,12 @@ public: result.append("maxWireVersion", WireSpec::instance().incomingExternalClient.maxWireVersion); result.append("minWireVersion", WireSpec::instance().incomingExternalClient.minWireVersion); - const auto parameter = mapFindWithDefault(ServerParameterSet::getGlobal()->getMap(), - "automationServiceDescriptor", - static_cast<ServerParameter*>(nullptr)); - if (parameter) - parameter->append(opCtx, result, "automationServiceDescriptor"); + { + const auto& serverParams = ServerParameterSet::getGlobal()->getMap(); + auto iter = serverParams.find("automationServiceDescriptor"); + if (iter != serverParams.end()) + iter->second->append(opCtx, result, "automationServiceDescriptor"); + } MessageCompressorManager::forSession(opCtx->getClient()->session()) .serverNegotiate(cmdObj, &result); diff --git a/src/mongo/scripting/bson_template_evaluator.cpp b/src/mongo/scripting/bson_template_evaluator.cpp index c46015f3fe4..37a1bffec84 100644 --- a/src/mongo/scripting/bson_template_evaluator.cpp +++ b/src/mongo/scripting/bson_template_evaluator.cpp @@ -33,7 +33,6 @@ #include <cstdlib> #include "mongo/base/static_assert.h" -#include "mongo/util/map_util.h" #include "mongo/util/str.h" namespace mongo { @@ -71,7 +70,8 @@ void BsonTemplateEvaluator::addOperator(const std::string& name, const OperatorF BsonTemplateEvaluator::OperatorFn BsonTemplateEvaluator::operatorEvaluator( const std::string& op) const { - return mapFindWithDefault(_operatorFunctions, op, OperatorFn()); + auto iter = _operatorFunctions.find(op); + return iter == _operatorFunctions.end() ? nullptr : iter->second; } /* This is the top level method for using this library. It takes a BSON Object as input, diff --git a/src/mongo/util/map_util.h b/src/mongo/util/map_util.h deleted file mode 100644 index 5825cfe79b8..00000000000 --- a/src/mongo/util/map_util.h +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * As a special exception, the copyright holders give permission to link the - * code of portions of this program with the OpenSSL library under certain - * conditions as described in each individual source file and distribute - * linked combinations including the program with the OpenSSL library. You - * must comply with the Server Side Public License in all respects for - * all of the code used other than as permitted herein. If you modify file(s) - * with this exception, you may extend this exception to your version of the - * file(s), but you are not obligated to do so. If you do not wish to do so, - * delete this exception statement from your version. If you delete this - * exception statement from all source files in the program, then also delete - * it in the license file. - */ - -#pragma once - -namespace mongo { - -/* - * If "myMap" contains "key", returns "myMap[key]". Otherwise, returns "defaultValue." - */ -template <typename M, typename K, typename V = typename M::mapped_type> -V mapFindWithDefault(const M& myMap, const K& key, const V& defaultValue = V()) { - typename M::const_iterator it = myMap.find(key); - if (it == myMap.end()) - return defaultValue; - return it->second; -} - -} // namespace mongo |