diff options
author | saturneric <[email protected]> | 2024-01-12 06:02:37 +0000 |
---|---|---|
committer | saturneric <[email protected]> | 2024-01-12 06:02:37 +0000 |
commit | bf538056b24a68b8fd235b1c50991ee8eb46a776 (patch) | |
tree | e1bab54095b80df62b321fb5bd69453f9f951b05 /src/core/module/GlobalRegisterTable.cpp | |
parent | feat: improve api and ui of keys import and export (diff) | |
download | GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.tar.gz GpgFrontend-bf538056b24a68b8fd235b1c50991ee8eb46a776.zip |
refactor: use QString instead of std::string and improve threading system
Diffstat (limited to 'src/core/module/GlobalRegisterTable.cpp')
-rw-r--r-- | src/core/module/GlobalRegisterTable.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/core/module/GlobalRegisterTable.cpp b/src/core/module/GlobalRegisterTable.cpp index b9fa3a1e..de058091 100644 --- a/src/core/module/GlobalRegisterTable.cpp +++ b/src/core/module/GlobalRegisterTable.cpp @@ -45,8 +45,7 @@ class GlobalRegisterTable::Impl { public: struct RTNode { std::optional<std::any> value = std::nullopt; - std::unordered_map<std::string, SecureUniquePtr<RTNode>> - children; + std::unordered_map<QString, SecureUniquePtr<RTNode>> children; int version = 0; const std::type_info* type = nullptr; }; @@ -54,9 +53,7 @@ class GlobalRegisterTable::Impl { explicit Impl(GlobalRegisterTable* parent) : parent_(parent) {} auto PublishKV(const Namespace& n, const Key& k, std::any v) -> bool { - std::istringstream iss(k); - std::string segment; - + QStringList const segments = k.split('.'); int version = 0; { @@ -66,7 +63,7 @@ class GlobalRegisterTable::Impl { .first->second; RTNode* current = root_rt_node.get(); - while (std::getline(iss, segment, '.')) { + for (const QString& segment : segments) { current = current->children .emplace(segment, SecureCreateUniqueObject<RTNode>()) .first->second.get(); @@ -74,7 +71,7 @@ class GlobalRegisterTable::Impl { current->value = v; current->type = &v.type(); - current->version++; + version = ++current->version; } emit parent_->SignalPublish(n, k, version, v); @@ -82,17 +79,16 @@ class GlobalRegisterTable::Impl { } auto LookupKV(const Namespace& n, const Key& k) -> std::optional<std::any> { - std::istringstream iss(k); - std::string segment; + QStringList const segments = k.split('.'); std::optional<std::any> rtn = std::nullopt; { - std::shared_lock lock(lock_); + std::shared_lock const lock(lock_); auto it = global_register_table_.find(n); if (it == global_register_table_.end()) return std::nullopt; RTNode* current = it->second.get(); - while (std::getline(iss, segment, '.')) { + for (const QString& segment : segments) { auto it = current->children.find(segment); if (it == current->children.end()) return std::nullopt; current = it->second.get(); @@ -103,8 +99,7 @@ class GlobalRegisterTable::Impl { } auto ListChildKeys(const Namespace& n, const Key& k) -> std::vector<Key> { - std::istringstream iss(k); - std::string segment; + QStringList const segments = k.split('.'); std::vector<Key> rtn; { @@ -113,7 +108,7 @@ class GlobalRegisterTable::Impl { if (it == global_register_table_.end()) return {}; RTNode* current = it->second.get(); - while (std::getline(iss, segment, '.')) { + for (const QString& segment : segments) { auto it = current->children.find(segment); if (it == current->children.end()) return {}; current = it->second.get(); |