From e7a8f64722f30528c0a6f2d7de370aab5010b8cc Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 16 Sep 2015 22:32:02 +0100 Subject: [PATCH] Use a sorted IdMap for aliases --- src/alias_registry.cc | 12 ++++++------ src/alias_registry.hh | 10 +++++----- src/command_manager.cc | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/alias_registry.cc b/src/alias_registry.cc index 24cd2d1b..d4dd01a5 100644 --- a/src/alias_registry.cc +++ b/src/alias_registry.cc @@ -9,21 +9,21 @@ void AliasRegistry::add_alias(String alias, String command) { kak_assert(not alias.empty()); kak_assert(CommandManager::instance().command_defined(command)); - m_aliases[alias] = std::move(command); + m_aliases.append({std::move(alias), std::move(command) }, true); } -void AliasRegistry::remove_alias(const String& alias) +void AliasRegistry::remove_alias(StringView alias) { auto it = m_aliases.find(alias); if (it != m_aliases.end()) m_aliases.erase(it); } -StringView AliasRegistry::operator[](const String& alias) const +StringView AliasRegistry::operator[](StringView alias) const { auto it = m_aliases.find(alias); if (it != m_aliases.end()) - return it->second; + return it->value; else if (m_parent) return (*m_parent)[alias]; else @@ -38,8 +38,8 @@ Vector AliasRegistry::aliases_for(StringView command) const for (auto& alias : m_aliases) { - if (alias.second == command) - res.push_back(alias.first); + if (alias.value == command) + res.push_back(alias.key); } return res; diff --git a/src/alias_registry.hh b/src/alias_registry.hh index faf856d6..4b9239b5 100644 --- a/src/alias_registry.hh +++ b/src/alias_registry.hh @@ -3,7 +3,7 @@ #include "safe_ptr.hh" #include "string.hh" -#include "unordered_map.hh" +#include "id_map.hh" namespace Kakoune { @@ -13,10 +13,10 @@ class AliasRegistry : public SafeCountable public: AliasRegistry(AliasRegistry& parent) : m_parent(&parent) {} void add_alias(String alias, String command); - void remove_alias(const String& alias); - StringView operator[](const String& name) const; + void remove_alias(StringView alias); + StringView operator[](StringView name) const; - using AliasMap = UnorderedMap; + using AliasMap = IdMap; using iterator = AliasMap::const_iterator; iterator begin() const { return m_aliases.begin(); } iterator end() const { return m_aliases.end(); } @@ -28,7 +28,7 @@ private: AliasRegistry() {} SafePtr m_parent; - UnorderedMap m_aliases; + AliasMap m_aliases; }; } diff --git a/src/command_manager.cc b/src/command_manager.cc index 7a4033da..08589f0a 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -572,8 +572,8 @@ Completions CommandManager::complete(const Context& context, } for (auto& alias : context.aliases()) { - if (prefix_match(alias.first, prefix)) - result.candidates.push_back(alias.first); + if (prefix_match(alias.key, prefix)) + result.candidates.push_back(alias.key); } std::sort(result.candidates.begin(), result.candidates.end()); return result;