Skip to content

Commit

Permalink
SERVER-38248 Change StringMap implementation to absl::flat_hash_map
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikedin committed Dec 4, 2018
1 parent cf8fbf5 commit 279fba2
Show file tree
Hide file tree
Showing 17 changed files with 207 additions and 1,050 deletions.
3 changes: 2 additions & 1 deletion jstests/noPassthrough/durable_view_catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
pipeline: x.options.pipeline
};
}));
assert.eq(listedViews, expectedViews, "persisted view definitions not correctly loaded");
assert.sameMembers(
listedViews, expectedViews, "persisted view definitions not correctly loaded");

// Insert an invalid view definition directly into system.views to bypass normal validation.
assert.writeOK(viewsDB.system.views.insert({_id: "badView", pipeline: "badType"}));
Expand Down
4 changes: 4 additions & 0 deletions src/mongo/base/string_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ class StringData {
*/
constexpr friend StringData operator"" _sd(const char* c, std::size_t len);

explicit operator std::string() const {
return toString();
}

/**
* Constructs a StringData with begin and end iterators. begin points to the beginning of the
* string. end points to the position past the end of the string. In a null-terminated string,
Expand Down
20 changes: 10 additions & 10 deletions src/mongo/db/background.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ void BgInfo::awaitNoBgOps(stdx::unique_lock<stdx::mutex>& lk) {
_noOpsInProg.wait(lk);
}

void recordBeginAndInsert(BgInfoMap* bgiMap, StringData key) {
std::shared_ptr<BgInfo>& bgInfo = bgiMap->get(key);
void recordBeginAndInsert(BgInfoMap& bgiMap, StringData key) {
std::shared_ptr<BgInfo>& bgInfo = bgiMap[key];
if (!bgInfo)
bgInfo.reset(new BgInfo);
bgInfo->recordBegin();
}

void recordEndAndRemove(BgInfoMap* bgiMap, StringData key) {
BgInfoMapIterator iter = bgiMap->find(key);
fassert(17431, iter != bgiMap->end());
void recordEndAndRemove(BgInfoMap& bgiMap, StringData key) {
BgInfoMapIterator iter = bgiMap.find(key);
fassert(17431, iter != bgiMap.end());
if (0 == iter->second->recordEnd()) {
bgiMap->erase(iter);
bgiMap.erase(iter);
}
}

Expand Down Expand Up @@ -169,14 +169,14 @@ void BackgroundOperation::awaitNoBgOpInProgForNs(StringData ns) {

BackgroundOperation::BackgroundOperation(StringData ns) : _ns(ns) {
stdx::lock_guard<stdx::mutex> lk(m);
recordBeginAndInsert(&dbsInProg, _ns.db());
recordBeginAndInsert(&nsInProg, _ns.ns());
recordBeginAndInsert(dbsInProg, _ns.db());
recordBeginAndInsert(nsInProg, _ns.ns());
}

BackgroundOperation::~BackgroundOperation() {
stdx::lock_guard<stdx::mutex> lk(m);
recordEndAndRemove(&dbsInProg, _ns.db());
recordEndAndRemove(&nsInProg, _ns.ns());
recordEndAndRemove(dbsInProg, _ns.db());
recordEndAndRemove(nsInProg, _ns.ns());
}

void BackgroundOperation::dump(std::ostream& ss) {
Expand Down
7 changes: 3 additions & 4 deletions src/mongo/db/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,9 @@ void CommandRegistry::registerCommand(Command* command, StringData name, StringD
if (key.empty()) {
continue;
}
auto hashedKey = CommandMap::HashedKey(key);
auto iter = _commands.find(hashedKey);
invariant(iter == _commands.end(), str::stream() << "command name collision: " << key);
_commands[hashedKey] = command;

auto result = _commands.try_emplace(key, command);
invariant(result.second, str::stream() << "command name collision: " << key);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/mongo/db/matcher/matcher_type_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,11 @@ Status parseSingleType(BSONElement elt,
constexpr StringData MatcherTypeSet::kMatchesAllNumbersAlias;

const StringMap<BSONType> MatcherTypeSet::kJsonSchemaTypeAliasMap = {
{JSONSchemaParser::kSchemaTypeArray, BSONType::Array},
{JSONSchemaParser::kSchemaTypeBoolean, BSONType::Bool},
{JSONSchemaParser::kSchemaTypeNull, BSONType::jstNULL},
{JSONSchemaParser::kSchemaTypeObject, BSONType::Object},
{JSONSchemaParser::kSchemaTypeString, BSONType::String},
{std::string(JSONSchemaParser::kSchemaTypeArray), BSONType::Array},
{std::string(JSONSchemaParser::kSchemaTypeBoolean), BSONType::Bool},
{std::string(JSONSchemaParser::kSchemaTypeNull), BSONType::jstNULL},
{std::string(JSONSchemaParser::kSchemaTypeObject), BSONType::Object},
{std::string(JSONSchemaParser::kSchemaTypeString), BSONType::String},
};

StatusWith<MatcherTypeSet> MatcherTypeSet::fromStringAliases(std::set<StringData> typeAliases,
Expand Down
Loading

0 comments on commit 279fba2

Please sign in to comment.