Skip to content

Commit

Permalink
Use unordered_map for RecordableTypeId names
Browse files Browse the repository at this point in the history
Summary: Obvious minor optimization.

Reviewed By: hanghu

Differential Revision: D57542723

fbshipit-source-id: 32b6f19ea7fcf282f29d522c7d3fa0c3c0857ed6
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed May 20, 2024
1 parent 1134bd8 commit 2784c45
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions vrs/StreamId.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

#include "StreamId.h"

#include <map>
#include <string>
#include <unordered_map>

#include <fmt/format.h>

Expand All @@ -27,8 +27,8 @@ namespace vrs {

namespace {

const map<RecordableTypeId, const char*>& getRecordableTypeIdRegistry() {
static const map<RecordableTypeId, const char*> sRegistry = {
const unordered_map<RecordableTypeId, const char*>& getRecordableTypeIdRegistry() {
static const unordered_map<RecordableTypeId, const char*> sRegistry = {
{RecordableTypeId::Undefined, "Undefined"},
{RecordableTypeId::VRSIndex, "VRS Index"}, // should probably not happen
{RecordableTypeId::VRSDescription, "VRS Description"}, // should probably not happen
Expand Down Expand Up @@ -189,7 +189,7 @@ StreamId fromNumericNameWithSeparator(const string& numericName, uint8_t separat
} // namespace

string toString(RecordableTypeId typeId) {
const map<RecordableTypeId, const char*>& registry = getRecordableTypeIdRegistry();
const unordered_map<RecordableTypeId, const char*>& registry = getRecordableTypeIdRegistry();
auto iter = registry.find(typeId);
if (iter != registry.end()) {
return iter->second;
Expand All @@ -198,7 +198,7 @@ string toString(RecordableTypeId typeId) {
}

bool StreamId::isKnownTypeId(RecordableTypeId typeId) {
const map<RecordableTypeId, const char*>& registry = getRecordableTypeIdRegistry();
const unordered_map<RecordableTypeId, const char*>& registry = getRecordableTypeIdRegistry();
return registry.find(typeId) != registry.end();
}

Expand Down

0 comments on commit 2784c45

Please sign in to comment.