diff --git a/src/alias_registry.cc b/src/alias_registry.cc index d4dd01a5..bcb6b9fd 100644 --- a/src/alias_registry.cc +++ b/src/alias_registry.cc @@ -9,7 +9,7 @@ void AliasRegistry::add_alias(String alias, String command) { kak_assert(not alias.empty()); kak_assert(CommandManager::instance().command_defined(command)); - m_aliases.append({std::move(alias), std::move(command) }, true); + m_aliases.append({std::move(alias), std::move(command) }); } void AliasRegistry::remove_alias(StringView alias) diff --git a/src/client.cc b/src/client.cc index d85606a3..38cc7d89 100644 --- a/src/client.cc +++ b/src/client.cc @@ -26,8 +26,6 @@ Client::Client(std::unique_ptr&& ui, std::move(name)}, m_env_vars(env_vars) { - m_env_vars.sort(); - context().set_client(*this); context().set_window(*m_window); diff --git a/src/env_vars.cc b/src/env_vars.cc index 4e4e4bdc..0e5c53e8 100644 --- a/src/env_vars.cc +++ b/src/env_vars.cc @@ -18,7 +18,6 @@ EnvVarMap get_env_vars() ++value; env_vars.append({{name, value}, (*value == '=') ? value+1 : String{}}); } - env_vars.sort(); return env_vars; } diff --git a/src/id_map.hh b/src/id_map.hh index 03e03353..b297ea59 100644 --- a/src/id_map.hh +++ b/src/id_map.hh @@ -16,10 +16,10 @@ public: struct Element { Element(String k, Value v) - : key(std::move(k)), hash(hash_value(key)), value(std::move(v)) {} + : hash(hash_value(k)), key(std::move(k)), value(std::move(v)) {} - String key; size_t hash; + String key; Value value; bool operator==(const Element& other) const @@ -32,69 +32,26 @@ public: using iterator = typename container_type::iterator; using const_iterator = typename container_type::const_iterator; - IdMap() : m_sorted(true) {} + IdMap() = default; - IdMap(std::initializer_list val) - : m_content{val}, - m_sorted(std::is_sorted(begin(), end(), cmp_hashes)) - {} + IdMap(std::initializer_list val) : m_content{val} {} - bool sorted() const { return m_sorted; } - void assume_sorted() + void append(const Element& value) { - kak_assert(std::is_sorted(begin(), end(), cmp_hashes)); - m_sorted = true; + m_content.push_back(value); } - void append(const Element& value, bool keep_sorted = false) + void append(Element&& value) { - if (keep_sorted and m_sorted) - { - auto it = std::lower_bound(begin(), end(), value.hash, - [](const Element& e, size_t hash) - { return e.hash < hash; }); - m_content.insert(it, value); - } - else - { - m_content.push_back(value); - m_sorted = false; - } - } - - void append(Element&& value, bool keep_sorted = false) - { - if (keep_sorted and m_sorted) - { - auto it = std::lower_bound(begin(), end(), value, cmp_hashes); - m_content.insert(it, std::move(value)); - } - else - { - m_content.push_back(std::move(value)); - m_sorted = false; - } + m_content.push_back(std::move(value)); } iterator find(StringView id) { const size_t hash = hash_value(id); - if (m_sorted) - { - auto it = std::lower_bound(begin(), end(), hash, - [](const Element& e, size_t hash) - { return e.hash < hash; }); - for (auto e = end(); it != e and it->hash == hash; ++it) - { - if (it->key == id) - return it; - } - return end(); - } - else - return std::find_if(begin(), end(), - [id, hash](const Element& e) - { return e.hash == hash and e.key == id; }); + return std::find_if(begin(), end(), + [id, hash](const Element& e) + { return e.hash == hash and e.key == id; }); } const_iterator find(StringView id) const @@ -144,12 +101,6 @@ public: return not (*this == other); } - void sort() - { - std::sort(begin(), end(), cmp_hashes); - m_sorted = true; - } - void reserve(size_t size) { m_content.reserve(size); } size_t size() const { return m_content.size(); } void clear() { m_content.clear(); } @@ -165,13 +116,7 @@ public: const_iterator end() const { return m_content.end(); } private: - static bool cmp_hashes(const Element& lhs, const Element& rhs) - { - return lhs.hash < rhs.hash; - } - container_type m_content; - bool m_sorted; }; } diff --git a/src/remote.cc b/src/remote.cc index fbf39d0c..0592d0a3 100644 --- a/src/remote.cc +++ b/src/remote.cc @@ -89,7 +89,6 @@ public: void write(const IdMap& map) { write(map.size()); - write(map.sorted()); for (auto& val : map) { write(val.key); @@ -221,7 +220,6 @@ template IdMap read_idmap(int socket) { uint32_t size = read(socket); - bool sorted = read(socket); IdMap res; res.reserve(size); while (size--) @@ -230,8 +228,6 @@ IdMap read_idmap(int socket) auto val = read(socket); res.append({std::move(key), std::move(val)}); } - if (sorted) - res.assume_sorted(); return res; }