[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

@@ -53,7 +53,7 @@ static void WorkspaceInit() {
}
for (auto&& root : gContext->storageRoots) {
root.getValue()->Apply();
root.second->Apply();
}
}
@@ -176,7 +176,7 @@ static bool LoadStorageImpl(Context* ctx, std::string_view dir,
bool rv = true;
for (auto&& root : ctx->storageRoots) {
std::string filename;
auto rootName = root.getKey();
auto& rootName = root.first;
if (rootName.empty()) {
filename = (fs::path{dir} / fmt::format("{}.json", name)).string();
} else {
@@ -291,7 +291,7 @@ static bool SaveStorageImpl(Context* ctx, std::string_view dir,
if (exiting && wpi::gui::gContext->resetOnExit) {
fs::remove(dirPath / fmt::format("{}-window.json", name), ec);
for (auto&& root : ctx->storageRoots) {
auto rootName = root.getKey();
auto& rootName = root.first;
if (rootName.empty()) {
fs::remove(dirPath / fmt::format("{}.json", name), ec);
} else {
@@ -304,14 +304,14 @@ static bool SaveStorageImpl(Context* ctx, std::string_view dir,
(dirPath / fmt::format("{}-window.json", name)).string());
for (auto&& root : ctx->storageRoots) {
auto rootName = root.getKey();
auto& rootName = root.first;
std::string filename;
if (rootName.empty()) {
filename = (dirPath / fmt::format("{}.json", name)).string();
} else {
filename = (dirPath / fmt::format("{}-{}.json", name, rootName)).string();
}
if (!SaveStorageRootImpl(ctx, filename, *root.getValue())) {
if (!SaveStorageRootImpl(ctx, filename, *root.second)) {
rv = false;
}
}
@@ -320,8 +320,7 @@ static bool SaveStorageImpl(Context* ctx, std::string_view dir,
Context::Context()
: sourceNameStorage{storageRoots.insert({"", std::make_unique<Storage>()})
.first->getValue()
->GetChild("sourceNames")} {
.first->second->GetChild("sourceNames")} {
storageStack.emplace_back(storageRoots[""].get());
// override ImGui ini saving

View File

@@ -112,5 +112,5 @@ DataSource* DataSource::Find(std::string_view id) {
if (it == gContext->sources.end()) {
return nullptr;
}
return it->getValue();
return it->second;
}

View File

@@ -331,7 +331,7 @@ std::vector<std::unique_ptr<Storage>>& Storage::GetChildArray(
std::unique_ptr<Storage::Value> Storage::Erase(std::string_view key) {
auto it = m_values.find(key);
if (it != m_values.end()) {
auto rv = std::move(it->getValue());
auto rv = std::move(it->second);
m_values.erase(it);
return rv;
}
@@ -339,11 +339,9 @@ std::unique_ptr<Storage::Value> Storage::Erase(std::string_view key) {
}
void Storage::EraseChildren() {
for (auto&& kv : m_values) {
if (kv.getValue()->type == Value::kChild) {
m_values.remove(&kv);
}
}
std::erase_if(m_values, [](const auto& kv) {
return kv.second->type == Value::kChild;
});
}
static bool JsonArrayToStorage(Storage::Value* valuePtr, const wpi::json& jarr,
@@ -559,7 +557,7 @@ wpi::json Storage::ToJson() const {
wpi::json j = wpi::json::object();
for (auto&& kv : m_values) {
wpi::json jelem;
auto& value = *kv.getValue();
auto& value = *kv.second;
switch (value.type) {
#define CASE(CapsName, LowerName) \
case Value::k##CapsName: \
@@ -602,7 +600,7 @@ wpi::json Storage::ToJson() const {
default:
continue;
}
j.emplace(kv.getKey(), std::move(jelem));
j.emplace(kv.first, std::move(jelem));
}
return j;
}
@@ -617,7 +615,7 @@ void Storage::Clear() {
void Storage::ClearValues() {
for (auto&& kv : m_values) {
auto& value = *kv.getValue();
auto& value = *kv.second;
switch (value.type) {
case Value::kInt:
value.intVal = value.intDefault;
@@ -703,7 +701,7 @@ void Storage::Apply() {
void Storage::ApplyChildren() {
for (auto&& kv : m_values) {
auto& value = *kv.getValue();
auto& value = *kv.second;
switch (value.type) {
case Value::kChild:
value.child->Apply();