[wpiutil] Replace LLVM StringMap impl with std::map

As string_view operations on std::map<std::string> won't be integrated
until C++26, placeholder implementations are used which are less efficient
in a couple of situations (e.g. insert with hint).
This commit is contained in:
Peter Johnson
2024-10-23 21:33:12 -07:00
parent 5f3cf517d3
commit f620141e0d
34 changed files with 944 additions and 2031 deletions

View File

@@ -49,8 +49,8 @@ void Tracer::PrintEpochs(wpi::raw_ostream& os) {
m_lastEpochsPrintTime = now;
for (const auto& epoch : m_epochs) {
os << fmt::format(
"\t{}: {:.6f}s\n", epoch.getKey(),
duration_cast<microseconds>(epoch.getValue()).count() / 1.0e6);
"\t{}: {:.6f}s\n", epoch.first,
duration_cast<microseconds>(epoch.second).count() / 1.0e6);
}
}
}

View File

@@ -46,7 +46,7 @@ void ShuffleboardComponentBase::BuildMetadata(
if (GetProperties().size() > 0) {
auto propTable = metaTable->GetSubTable("Properties");
for (auto& entry : GetProperties()) {
propTable->GetEntry(entry.first()).SetValue(entry.second);
propTable->GetEntry(entry.first).SetValue(entry.second);
}
}
m_metadataDirty = false;

View File

@@ -51,7 +51,7 @@ void Mechanism2d::InitSendable(nt::NTSendableBuilder& builder) {
m_colorPub = m_table->GetStringTopic(kBackgroundColor).Publish();
m_colorPub.Set(m_color);
for (const auto& entry : m_roots) {
const auto& root = entry.getValue().get();
root->Update(m_table->GetSubTable(entry.getKey()));
const auto& root = entry.second.get();
root->Update(m_table->GetSubTable(entry.first));
}
}

View File

@@ -18,8 +18,7 @@ void MechanismObject2d::Update(std::shared_ptr<nt::NetworkTable> table) {
std::scoped_lock lock(m_mutex);
m_table = table;
UpdateEntries(m_table);
for (const wpi::StringMapEntry<std::unique_ptr<MechanismObject2d>>& entry :
m_objects) {
entry.getValue()->Update(m_table->GetSubTable(entry.getKey()));
for (const auto& entry : m_objects) {
entry.second->Update(m_table->GetSubTable(entry.first));
}
}

View File

@@ -126,7 +126,7 @@ wpi::Sendable* SmartDashboard::GetData(std::string_view key) {
if (it == inst.tablesToData.end()) {
throw FRC_MakeError(err::SmartDashboardMissingKey, "{}", key);
}
return wpi::SendableRegistry::GetSendable(it->getValue());
return wpi::SendableRegistry::GetSendable(it->second);
}
bool SmartDashboard::PutBoolean(std::string_view keyName, bool value) {
@@ -254,6 +254,6 @@ void SmartDashboard::UpdateValues() {
inst.listenerExecutor.RunListenerTasks();
std::scoped_lock lock(inst.tablesToDataMutex);
for (auto& i : inst.tablesToData) {
wpi::SendableRegistry::Update(i.getValue());
wpi::SendableRegistry::Update(i.second);
}
}

View File

@@ -49,7 +49,7 @@ class SendableChooser : public SendableChooserBase {
}
public:
using CopyType = decltype(_unwrap_smart_ptr(m_choices.lookup("")));
using CopyType = decltype(_unwrap_smart_ptr(m_choices.find("")->second));
SendableChooser() = default;
~SendableChooser() override = default;
@@ -105,7 +105,11 @@ class SendableChooser : public SendableChooserBase {
if (selected.empty()) {
return CopyType{};
} else {
return _unwrap_smart_ptr(m_choices.lookup(selected));
auto it = m_choices.find(selected);
if (it == m_choices.end()) {
return CopyType{};
}
return _unwrap_smart_ptr(it->second);
}
}
@@ -128,13 +132,8 @@ class SendableChooser : public SendableChooserBase {
[=, this] {
std::vector<std::string> keys;
for (const auto& choice : m_choices) {
keys.emplace_back(choice.first());
keys.emplace_back(choice.first);
}
// Unlike std::map, wpi::StringMap elements
// are not sorted
std::sort(keys.begin(), keys.end());
return keys;
},
nullptr);