Replace uses of UnorderedMap with HashMap
This commit is contained in:
parent
e9f93f1b2f
commit
6373338c50
|
@ -437,13 +437,13 @@ void CommandManager::execute_single_command(CommandParameters params,
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ParametersParser parameter_parser(param_view,
|
ParametersParser parameter_parser(param_view,
|
||||||
command_it->second.param_desc);
|
command_it->value.param_desc);
|
||||||
command_it->second.command(parameter_parser, context, shell_context);
|
command_it->value.command(parameter_parser, context, shell_context);
|
||||||
}
|
}
|
||||||
catch (runtime_error& error)
|
catch (runtime_error& error)
|
||||||
{
|
{
|
||||||
throw runtime_error(format("{}:{}: '{}' {}", pos.line+1, pos.column+1,
|
throw runtime_error(format("{}:{}: '{}' {}", pos.line+1, pos.column+1,
|
||||||
command_it->first, error.what()));
|
command_it->key, error.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -507,11 +507,11 @@ Optional<CommandInfo> CommandManager::command_info(const Context& context, Strin
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
CommandInfo res;
|
CommandInfo res;
|
||||||
res.name = cmd->first;
|
res.name = cmd->key;
|
||||||
if (not cmd->second.docstring.empty())
|
if (not cmd->value.docstring.empty())
|
||||||
res.info += cmd->second.docstring + "\n";
|
res.info += cmd->value.docstring + "\n";
|
||||||
|
|
||||||
if (cmd->second.helper)
|
if (cmd->value.helper)
|
||||||
{
|
{
|
||||||
Vector<String> params;
|
Vector<String> params;
|
||||||
for (auto it = tokens.begin() + cmd_idx + 1;
|
for (auto it = tokens.begin() + cmd_idx + 1;
|
||||||
|
@ -523,7 +523,7 @@ Optional<CommandInfo> CommandManager::command_info(const Context& context, Strin
|
||||||
it->type() == Token::Type::RawEval)
|
it->type() == Token::Type::RawEval)
|
||||||
params.push_back(it->content());
|
params.push_back(it->content());
|
||||||
}
|
}
|
||||||
String helpstr = cmd->second.helper(context, params);
|
String helpstr = cmd->value.helper(context, params);
|
||||||
if (not helpstr.empty())
|
if (not helpstr.empty())
|
||||||
{
|
{
|
||||||
if (helpstr.back() != '\n')
|
if (helpstr.back() != '\n')
|
||||||
|
@ -533,13 +533,13 @@ Optional<CommandInfo> CommandManager::command_info(const Context& context, Strin
|
||||||
}
|
}
|
||||||
|
|
||||||
String aliases;
|
String aliases;
|
||||||
for (auto& alias : context.aliases().aliases_for(cmd->first))
|
for (auto& alias : context.aliases().aliases_for(cmd->key))
|
||||||
aliases += " " + alias;
|
aliases += " " + alias;
|
||||||
if (not aliases.empty())
|
if (not aliases.empty())
|
||||||
res.info += "Aliases:" + aliases + "\n";
|
res.info += "Aliases:" + aliases + "\n";
|
||||||
|
|
||||||
|
|
||||||
auto& switches = cmd->second.param_desc.switches;
|
auto& switches = cmd->value.param_desc.switches;
|
||||||
if (not switches.empty())
|
if (not switches.empty())
|
||||||
{
|
{
|
||||||
res.info += "Switches:\n";
|
res.info += "Switches:\n";
|
||||||
|
@ -553,8 +553,8 @@ Completions CommandManager::complete_command_name(const Context& context,
|
||||||
StringView query, bool with_aliases) const
|
StringView query, bool with_aliases) const
|
||||||
{
|
{
|
||||||
auto commands = m_commands
|
auto commands = m_commands
|
||||||
| filter([](const CommandMap::value_type& cmd) { return not (cmd.second.flags & CommandFlags::Hidden); })
|
| filter([](const CommandMap::Item& cmd) { return not (cmd.value.flags & CommandFlags::Hidden); })
|
||||||
| transform(std::mem_fn(&CommandMap::value_type::first));
|
| transform(std::mem_fn(&CommandMap::Item::key));
|
||||||
|
|
||||||
if (not with_aliases)
|
if (not with_aliases)
|
||||||
return {0, query.length(), Kakoune::complete(query, query.length(), commands)};
|
return {0, query.length(), Kakoune::complete(query, query.length(), commands)};
|
||||||
|
@ -636,7 +636,7 @@ Completions CommandManager::complete(const Context& context,
|
||||||
|
|
||||||
auto command_it = find_command(context, command_name);
|
auto command_it = find_command(context, command_name);
|
||||||
if (command_it == m_commands.end() or
|
if (command_it == m_commands.end() or
|
||||||
not command_it->second.completer)
|
not command_it->value.completer)
|
||||||
return Completions();
|
return Completions();
|
||||||
|
|
||||||
Vector<String> params;
|
Vector<String> params;
|
||||||
|
@ -644,7 +644,7 @@ Completions CommandManager::complete(const Context& context,
|
||||||
params.push_back(it->content());
|
params.push_back(it->content());
|
||||||
if (tok_idx == tokens.size())
|
if (tok_idx == tokens.size())
|
||||||
params.emplace_back("");
|
params.emplace_back("");
|
||||||
Completions completions = offset_pos(command_it->second.completer(
|
Completions completions = offset_pos(command_it->value.completer(
|
||||||
context, flags, params, tok_idx - cmd_idx - 1,
|
context, flags, params, tok_idx - cmd_idx - 1,
|
||||||
cursor_pos_in_token), start);
|
cursor_pos_in_token), start);
|
||||||
|
|
||||||
|
@ -683,8 +683,8 @@ Completions CommandManager::complete(const Context& context,
|
||||||
}
|
}
|
||||||
|
|
||||||
auto command_it = find_command(context, command_name);
|
auto command_it = find_command(context, command_name);
|
||||||
if (command_it != m_commands.end() and command_it->second.completer)
|
if (command_it != m_commands.end() and command_it->value.completer)
|
||||||
return command_it->second.completer(
|
return command_it->value.completer(
|
||||||
context, flags, params.subrange(1),
|
context, flags, params.subrange(1),
|
||||||
token_to_complete-1, pos_in_token);
|
token_to_complete-1, pos_in_token);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "optional.hh"
|
#include "optional.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <initializer_list>
|
#include <initializer_list>
|
||||||
|
@ -123,7 +123,7 @@ private:
|
||||||
CommandHelper helper;
|
CommandHelper helper;
|
||||||
CommandCompleter completer;
|
CommandCompleter completer;
|
||||||
};
|
};
|
||||||
using CommandMap = UnorderedMap<String, CommandDescriptor, MemoryDomain::Commands>;
|
using CommandMap = HashMap<String, CommandDescriptor, MemoryDomain::Commands>;
|
||||||
CommandMap m_commands;
|
CommandMap m_commands;
|
||||||
String m_last_complete_command;
|
String m_last_complete_command;
|
||||||
int m_command_depth = 0;
|
int m_command_depth = 0;
|
||||||
|
|
|
@ -1780,7 +1780,7 @@ const CommandDesc prompt_cmd = {
|
||||||
(event == PromptEvent::Change and on_change.empty()))
|
(event == PromptEvent::Change and on_change.empty()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& text = sc.env_vars["text"] = str.str();
|
auto& text = sc.env_vars["text"_sv] = str.str();
|
||||||
auto clear_password = on_scope_end([&] {
|
auto clear_password = on_scope_end([&] {
|
||||||
if (flags & PromptFlags::Password)
|
if (flags & PromptFlags::Password)
|
||||||
memset(text.data(), 0, (int)text.length());
|
memset(text.data(), 0, (int)text.length());
|
||||||
|
@ -1872,7 +1872,7 @@ const CommandDesc on_key_cmd = {
|
||||||
CapturedShellContext sc{shell_context};
|
CapturedShellContext sc{shell_context};
|
||||||
context.input_handler().on_next_key(
|
context.input_handler().on_next_key(
|
||||||
KeymapMode::None, [=](Key key, Context& context) mutable {
|
KeymapMode::None, [=](Key key, Context& context) mutable {
|
||||||
sc.env_vars["key"] = key_to_str(key);
|
sc.env_vars["key"_sv] = key_to_str(key);
|
||||||
ScopedSetBool disable_history{context.history_disabled()};
|
ScopedSetBool disable_history{context.history_disabled()};
|
||||||
|
|
||||||
CommandManager::instance().execute(command, context, sc);
|
CommandManager::instance().execute(command, context, sc);
|
||||||
|
|
|
@ -48,9 +48,9 @@ Face FaceRegistry::operator[](const String& facedesc)
|
||||||
auto it = m_aliases.find(facedesc);
|
auto it = m_aliases.find(facedesc);
|
||||||
while (it != m_aliases.end())
|
while (it != m_aliases.end())
|
||||||
{
|
{
|
||||||
if (it->second.alias.empty())
|
if (it->value.alias.empty())
|
||||||
return it->second.face;
|
return it->value.face;
|
||||||
it = m_aliases.find(it->second.alias);
|
it = m_aliases.find(it->value.alias);
|
||||||
}
|
}
|
||||||
return parse_face(facedesc);
|
return parse_face(facedesc);
|
||||||
}
|
}
|
||||||
|
@ -75,11 +75,11 @@ void FaceRegistry::register_alias(const String& name, const String& facedesc,
|
||||||
{
|
{
|
||||||
while (it != m_aliases.end())
|
while (it != m_aliases.end())
|
||||||
{
|
{
|
||||||
if (it->second.alias.empty())
|
if (it->value.alias.empty())
|
||||||
break;
|
break;
|
||||||
if (it->second.alias == name)
|
if (it->value.alias == name)
|
||||||
throw runtime_error("face cycle detected");
|
throw runtime_error("face cycle detected");
|
||||||
it = m_aliases.find(it->second.alias);
|
it = m_aliases.find(it->value.alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
alias.alias = facedesc;
|
alias.alias = facedesc;
|
||||||
|
@ -95,7 +95,7 @@ CandidateList FaceRegistry::complete_alias_name(StringView prefix,
|
||||||
ByteCount cursor_pos) const
|
ByteCount cursor_pos) const
|
||||||
{
|
{
|
||||||
return complete(prefix, cursor_pos,
|
return complete(prefix, cursor_pos,
|
||||||
m_aliases | transform(std::mem_fn(&AliasMap::value_type::first)));
|
m_aliases | transform(std::mem_fn(&AliasMap::Item::key)));
|
||||||
}
|
}
|
||||||
|
|
||||||
FaceRegistry::FaceRegistry()
|
FaceRegistry::FaceRegistry()
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "face.hh"
|
#include "face.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include "completion.hh"
|
#include "completion.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -29,7 +29,7 @@ private:
|
||||||
FaceOrAlias(Face face = Face{}) : face(face) {}
|
FaceOrAlias(Face face = Face{}) : face(face) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
using AliasMap = UnorderedMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
using AliasMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
||||||
AliasMap m_aliases;
|
AliasMap m_aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -477,7 +477,7 @@ CandidateList complete_command(StringView prefix, ByteCount cursor_pos)
|
||||||
TimeSpec mtim = {};
|
TimeSpec mtim = {};
|
||||||
Vector<String> commands;
|
Vector<String> commands;
|
||||||
};
|
};
|
||||||
static UnorderedMap<String, CommandCache, MemoryDomain::Commands> command_cache;
|
static HashMap<String, CommandCache, MemoryDomain::Commands> command_cache;
|
||||||
|
|
||||||
Vector<RankedMatch> matches;
|
Vector<RankedMatch> matches;
|
||||||
for (auto dir : StringView{getenv("PATH")} | split<StringView>(':'))
|
for (auto dir : StringView{getenv("PATH")} | split<StringView>(':'))
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "unit_tests.hh"
|
#include "unit_tests.hh"
|
||||||
|
|
||||||
#include <random>
|
#include <random>
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -148,7 +149,7 @@ void profile_hash_maps()
|
||||||
{
|
{
|
||||||
for (auto i : { 1000, 10000, 100000, 1000000, 10000000 })
|
for (auto i : { 1000, 10000, 100000, 1000000, 10000000 })
|
||||||
{
|
{
|
||||||
do_profile<UnorderedMap<size_t, size_t>>(i, "UnorderedMap");
|
do_profile<std::unordered_map<size_t, size_t>>(i, "UnorderedMap");
|
||||||
do_profile<HashMap<size_t, size_t>>(i, " HashMap ");
|
do_profile<HashMap<size_t, size_t>>(i, " HashMap ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,15 +128,18 @@ private:
|
||||||
Vector<Entry, domain> m_entries;
|
Vector<Entry, domain> m_entries;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Key, typename Value, MemoryDomain domain = MemoryDomain::Undefined>
|
template<typename Key, typename Value>
|
||||||
struct HashMap
|
struct HashItem
|
||||||
{
|
|
||||||
struct Item
|
|
||||||
{
|
{
|
||||||
Key key;
|
Key key;
|
||||||
Value value;
|
Value value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename Key, typename Value, MemoryDomain domain = MemoryDomain::Undefined>
|
||||||
|
struct HashMap
|
||||||
|
{
|
||||||
|
using Item = HashItem<Key, Value>;
|
||||||
|
|
||||||
HashMap() = default;
|
HashMap() = default;
|
||||||
|
|
||||||
HashMap(std::initializer_list<Item> val) : m_items{val}
|
HashMap(std::initializer_list<Item> val) : m_items{val}
|
||||||
|
|
|
@ -1425,7 +1425,7 @@ private:
|
||||||
{
|
{
|
||||||
size_t timestamp = 0;
|
size_t timestamp = 0;
|
||||||
Vector<RegionMatches, MemoryDomain::Highlight> matches;
|
Vector<RegionMatches, MemoryDomain::Highlight> matches;
|
||||||
UnorderedMap<BufferRange, RegionList, MemoryDomain::Highlight> regions;
|
HashMap<BufferRange, RegionList, MemoryDomain::Highlight> regions;
|
||||||
};
|
};
|
||||||
BufferSideCache<Cache> m_cache;
|
BufferSideCache<Cache> m_cache;
|
||||||
|
|
||||||
|
@ -1471,7 +1471,7 @@ private:
|
||||||
|
|
||||||
auto it = cache.regions.find(range);
|
auto it = cache.regions.find(range);
|
||||||
if (it != cache.regions.end())
|
if (it != cache.regions.end())
|
||||||
return it->second;
|
return it->value;
|
||||||
|
|
||||||
RegionList& regions = cache.regions[range];
|
RegionList& regions = cache.regions[range];
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "normal.hh"
|
#include "normal.hh"
|
||||||
#include "regex.hh"
|
#include "regex.hh"
|
||||||
#include "register_manager.hh"
|
#include "register_manager.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
#include "utf8.hh"
|
#include "utf8.hh"
|
||||||
#include "window.hh"
|
#include "window.hh"
|
||||||
|
@ -944,7 +944,7 @@ private:
|
||||||
PromptFlags m_flags;
|
PromptFlags m_flags;
|
||||||
|
|
||||||
using History = Vector<String, MemoryDomain::History>;
|
using History = Vector<String, MemoryDomain::History>;
|
||||||
static UnorderedMap<String, History, MemoryDomain::History> ms_history;
|
static HashMap<String, History, MemoryDomain::History> ms_history;
|
||||||
History::iterator m_history_it;
|
History::iterator m_history_it;
|
||||||
|
|
||||||
void history_push(History& history, StringView entry)
|
void history_push(History& history, StringView entry)
|
||||||
|
@ -959,7 +959,7 @@ private:
|
||||||
history.push_back(entry.str());
|
history.push_back(entry.str());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
UnorderedMap<String, Prompt::History, MemoryDomain::History> Prompt::ms_history;
|
HashMap<String, Prompt::History, MemoryDomain::History> Prompt::ms_history;
|
||||||
|
|
||||||
class NextKey : public InputMode
|
class NextKey : public InputMode
|
||||||
{
|
{
|
||||||
|
|
|
@ -91,7 +91,7 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
|
||||||
|
|
||||||
BufferCoord word_begin;
|
BufferCoord word_begin;
|
||||||
StringView prefix;
|
StringView prefix;
|
||||||
UnorderedMap<StringView, int> sel_word_counts;
|
HashMap<StringView, int> sel_word_counts;
|
||||||
for (int i = 0; i < sels.size(); ++i)
|
for (int i = 0; i < sels.size(); ++i)
|
||||||
{
|
{
|
||||||
Utf8It end{buffer.iterator_at(sels[i].cursor()), buffer};
|
Utf8It end{buffer.iterator_at(sels[i].cursor()), buffer};
|
||||||
|
@ -136,8 +136,8 @@ InsertCompletion complete_word(const SelectionList& sels, const OptionManager& o
|
||||||
// Remove words that are being edited
|
// Remove words that are being edited
|
||||||
for (auto& word_count : sel_word_counts)
|
for (auto& word_count : sel_word_counts)
|
||||||
{
|
{
|
||||||
if (get_word_db(buffer).get_word_occurences(word_count.first) <= word_count.second)
|
if (get_word_db(buffer).get_word_occurences(word_count.key) <= word_count.value)
|
||||||
unordered_erase(matches, word_count.first);
|
unordered_erase(matches, word_count.key);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other_buffers)
|
if (other_buffers)
|
||||||
|
|
|
@ -348,16 +348,16 @@ void JsonUI::eval_json(const Value& json)
|
||||||
throw runtime_error("json request is not an object");
|
throw runtime_error("json request is not an object");
|
||||||
|
|
||||||
const JsonObject& object = json.as<JsonObject>();
|
const JsonObject& object = json.as<JsonObject>();
|
||||||
auto json_it = object.find("jsonrpc");
|
auto json_it = object.find("jsonrpc"_sv);
|
||||||
if (json_it == object.end() or json_it->value.as<String>() != "2.0")
|
if (json_it == object.end() or json_it->value.as<String>() != "2.0")
|
||||||
throw runtime_error("invalid json rpc request");
|
throw runtime_error("invalid json rpc request");
|
||||||
|
|
||||||
auto method_it = object.find("method");
|
auto method_it = object.find("method"_sv);
|
||||||
if (method_it == object.end())
|
if (method_it == object.end())
|
||||||
throw runtime_error("invalid json rpc request (method missing)");
|
throw runtime_error("invalid json rpc request (method missing)");
|
||||||
StringView method = method_it->value.as<String>();
|
StringView method = method_it->value.as<String>();
|
||||||
|
|
||||||
auto params_it = object.find("params");
|
auto params_it = object.find("params"_sv);
|
||||||
if (params_it == object.end())
|
if (params_it == object.end())
|
||||||
throw runtime_error("invalid json rpc request (params missing)");
|
throw runtime_error("invalid json rpc request (params missing)");
|
||||||
const JsonArray& params = params_it->value.as<JsonArray>();
|
const JsonArray& params = params_it->value.as<JsonArray>();
|
||||||
|
|
|
@ -11,27 +11,27 @@ namespace Kakoune
|
||||||
void KeymapManager::map_key(Key key, KeymapMode mode,
|
void KeymapManager::map_key(Key key, KeymapMode mode,
|
||||||
KeyList mapping, String docstring)
|
KeyList mapping, String docstring)
|
||||||
{
|
{
|
||||||
m_mapping[{key, mode}] = {std::move(mapping), std::move(docstring)};
|
m_mapping[KeyAndMode{key, mode}] = {std::move(mapping), std::move(docstring)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void KeymapManager::unmap_key(Key key, KeymapMode mode)
|
void KeymapManager::unmap_key(Key key, KeymapMode mode)
|
||||||
{
|
{
|
||||||
m_mapping.erase({key, mode});
|
m_mapping.unordered_remove(KeyAndMode{key, mode});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool KeymapManager::is_mapped(Key key, KeymapMode mode) const
|
bool KeymapManager::is_mapped(Key key, KeymapMode mode) const
|
||||||
{
|
{
|
||||||
return m_mapping.find({key, mode}) != m_mapping.end() or
|
return m_mapping.find(KeyAndMode{key, mode}) != m_mapping.end() or
|
||||||
(m_parent and m_parent->is_mapped(key, mode));
|
(m_parent and m_parent->is_mapped(key, mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
const KeymapManager::KeyMapInfo&
|
const KeymapManager::KeyMapInfo&
|
||||||
KeymapManager::get_mapping(Key key, KeymapMode mode) const
|
KeymapManager::get_mapping(Key key, KeymapMode mode) const
|
||||||
{
|
{
|
||||||
auto it = m_mapping.find({key, mode});
|
auto it = m_mapping.find(KeyAndMode{key, mode});
|
||||||
if (it != m_mapping.end())
|
if (it != m_mapping.end())
|
||||||
return it->second;
|
return it->value;
|
||||||
kak_assert(m_parent);
|
kak_assert(m_parent);
|
||||||
return m_parent->get_mapping(key, mode);
|
return m_parent->get_mapping(key, mode);
|
||||||
}
|
}
|
||||||
|
@ -43,8 +43,8 @@ KeymapManager::KeyList KeymapManager::get_mapped_keys(KeymapMode mode) const
|
||||||
res = m_parent->get_mapped_keys(mode);
|
res = m_parent->get_mapped_keys(mode);
|
||||||
for (auto& map : m_mapping)
|
for (auto& map : m_mapping)
|
||||||
{
|
{
|
||||||
if (map.first.second == mode)
|
if (map.key.second == mode)
|
||||||
res.emplace_back(map.first.first);
|
res.emplace_back(map.key.first);
|
||||||
}
|
}
|
||||||
std::sort(res.begin(), res.end());
|
std::sort(res.begin(), res.end());
|
||||||
res.erase(std::unique(res.begin(), res.end()), res.end());
|
res.erase(std::unique(res.begin(), res.end()), res.end());
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include "keys.hh"
|
#include "keys.hh"
|
||||||
#include "hash.hh"
|
#include "hash.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
#include "vector.hh"
|
#include "vector.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
|
@ -51,7 +51,7 @@ private:
|
||||||
|
|
||||||
KeymapManager* m_parent;
|
KeymapManager* m_parent;
|
||||||
using KeyAndMode = std::pair<Key, KeymapMode>;
|
using KeyAndMode = std::pair<Key, KeymapMode>;
|
||||||
UnorderedMap<KeyAndMode, KeyMapInfo, MemoryDomain::Mapping> m_mapping;
|
HashMap<KeyAndMode, KeyMapInfo, MemoryDomain::Mapping> m_mapping;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ int NCursesUI::get_color(Color color)
|
||||||
{
|
{
|
||||||
auto it = m_colors.find(color);
|
auto it = m_colors.find(color);
|
||||||
if (it != m_colors.end())
|
if (it != m_colors.end())
|
||||||
return it->second;
|
return it->value;
|
||||||
else if (m_change_colors and can_change_color() and COLORS > 16)
|
else if (m_change_colors and can_change_color() and COLORS > 16)
|
||||||
{
|
{
|
||||||
kak_assert(color.color == Color::RGB);
|
kak_assert(color.color == Color::RGB);
|
||||||
|
@ -171,7 +171,7 @@ int NCursesUI::get_color_pair(const Face& face)
|
||||||
ColorPair colors{face.fg, face.bg};
|
ColorPair colors{face.fg, face.bg};
|
||||||
auto it = m_colorpairs.find(colors);
|
auto it = m_colorpairs.find(colors);
|
||||||
if (it != m_colorpairs.end())
|
if (it != m_colorpairs.end())
|
||||||
return it->second;
|
return it->value;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
init_pair(m_next_pair, get_color(face.fg), get_color(face.bg));
|
init_pair(m_next_pair, get_color(face.fg), get_color(face.bg));
|
||||||
|
@ -214,7 +214,7 @@ void on_term_resize(int)
|
||||||
EventManager::instance().force_signal(0);
|
EventManager::instance().force_signal(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::initializer_list<std::pair<const Kakoune::Color, int>>
|
static const std::initializer_list<HashMap<Kakoune::Color, int>::Item>
|
||||||
default_colors = {
|
default_colors = {
|
||||||
{ Color::Default, -1 },
|
{ Color::Default, -1 },
|
||||||
{ Color::Black, COLOR_BLACK },
|
{ Color::Black, COLOR_BLACK },
|
||||||
|
@ -1005,7 +1005,7 @@ void NCursesUI::enable_mouse(bool enabled)
|
||||||
void NCursesUI::set_ui_options(const Options& options)
|
void NCursesUI::set_ui_options(const Options& options)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
auto it = options.find("ncurses_assistant");
|
auto it = options.find("ncurses_assistant"_sv);
|
||||||
if (it == options.end() or it->value == "clippy")
|
if (it == options.end() or it->value == "clippy")
|
||||||
m_assistant = assistant_clippy;
|
m_assistant = assistant_clippy;
|
||||||
else if (it->value == "cat")
|
else if (it->value == "cat")
|
||||||
|
@ -1015,19 +1015,19 @@ void NCursesUI::set_ui_options(const Options& options)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto it = options.find("ncurses_status_on_top");
|
auto it = options.find("ncurses_status_on_top"_sv);
|
||||||
m_status_on_top = it != options.end() and
|
m_status_on_top = it != options.end() and
|
||||||
(it->value == "yes" or it->value == "true");
|
(it->value == "yes" or it->value == "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto it = options.find("ncurses_set_title");
|
auto it = options.find("ncurses_set_title"_sv);
|
||||||
m_set_title = it == options.end() or
|
m_set_title = it == options.end() or
|
||||||
(it->value == "yes" or it->value == "true");
|
(it->value == "yes" or it->value == "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto it = options.find("ncurses_change_colors");
|
auto it = options.find("ncurses_change_colors"_sv);
|
||||||
auto value = it == options.end() or
|
auto value = it == options.end() or
|
||||||
(it->value == "yes" or it->value == "true");
|
(it->value == "yes" or it->value == "true");
|
||||||
|
|
||||||
|
@ -1045,16 +1045,16 @@ void NCursesUI::set_ui_options(const Options& options)
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
auto enable_mouse_it = options.find("ncurses_enable_mouse");
|
auto enable_mouse_it = options.find("ncurses_enable_mouse"_sv);
|
||||||
enable_mouse(enable_mouse_it == options.end() or
|
enable_mouse(enable_mouse_it == options.end() or
|
||||||
enable_mouse_it->value == "yes" or
|
enable_mouse_it->value == "yes" or
|
||||||
enable_mouse_it->value == "true");
|
enable_mouse_it->value == "true");
|
||||||
|
|
||||||
auto wheel_up_it = options.find("ncurses_wheel_up_button");
|
auto wheel_up_it = options.find("ncurses_wheel_up_button"_sv);
|
||||||
m_wheel_up_button = wheel_up_it != options.end() ?
|
m_wheel_up_button = wheel_up_it != options.end() ?
|
||||||
str_to_int_ifp(wheel_up_it->value).value_or(4) : 4;
|
str_to_int_ifp(wheel_up_it->value).value_or(4) : 4;
|
||||||
|
|
||||||
auto wheel_down_it = options.find("ncurses_wheel_down_button");
|
auto wheel_down_it = options.find("ncurses_wheel_down_button"_sv);
|
||||||
m_wheel_down_button = wheel_down_it != options.end() ?
|
m_wheel_down_button = wheel_down_it != options.end() ?
|
||||||
str_to_int_ifp(wheel_down_it->value).value_or(5) : 5;
|
str_to_int_ifp(wheel_down_it->value).value_or(5) : 5;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
#include "face.hh"
|
#include "face.hh"
|
||||||
#include "user_interface.hh"
|
#include "user_interface.hh"
|
||||||
#include "array_view.hh"
|
#include "array_view.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
|
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
@ -77,8 +77,8 @@ private:
|
||||||
DisplayCoord m_dimensions;
|
DisplayCoord m_dimensions;
|
||||||
|
|
||||||
using ColorPair = std::pair<Color, Color>;
|
using ColorPair = std::pair<Color, Color>;
|
||||||
UnorderedMap<Color, int, MemoryDomain::Faces> m_colors;
|
HashMap<Color, int, MemoryDomain::Faces> m_colors;
|
||||||
UnorderedMap<ColorPair, int, MemoryDomain::Faces> m_colorpairs;
|
HashMap<ColorPair, int, MemoryDomain::Faces> m_colorpairs;
|
||||||
int m_next_color = 16;
|
int m_next_color = 16;
|
||||||
int m_next_pair = 1;
|
int m_next_pair = 1;
|
||||||
int m_active_pair = -1;
|
int m_active_pair = -1;
|
||||||
|
|
|
@ -35,10 +35,10 @@ Register& RegisterManager::operator[](Codepoint c) const
|
||||||
if (it == m_registers.end())
|
if (it == m_registers.end())
|
||||||
throw runtime_error(format("no such register: '{}'", c));
|
throw runtime_error(format("no such register: '{}'", c));
|
||||||
|
|
||||||
return *(it->second);
|
return *(it->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegisterManager::add_register(char c, std::unique_ptr<Register> reg)
|
void RegisterManager::add_register(Codepoint c, std::unique_ptr<Register> reg)
|
||||||
{
|
{
|
||||||
auto& reg_ptr = m_registers[c];
|
auto& reg_ptr = m_registers[c];
|
||||||
kak_assert(not reg_ptr);
|
kak_assert(not reg_ptr);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "array_view.hh"
|
#include "array_view.hh"
|
||||||
#include "exception.hh"
|
#include "exception.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "vector.hh"
|
#include "vector.hh"
|
||||||
|
|
||||||
|
@ -100,10 +100,10 @@ class RegisterManager : public Singleton<RegisterManager>
|
||||||
public:
|
public:
|
||||||
Register& operator[](StringView reg) const;
|
Register& operator[](StringView reg) const;
|
||||||
Register& operator[](Codepoint c) const;
|
Register& operator[](Codepoint c) const;
|
||||||
void add_register(char c, std::unique_ptr<Register> reg);
|
void add_register(Codepoint c, std::unique_ptr<Register> reg);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
UnorderedMap<char, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
|
HashMap<Codepoint, std::unique_ptr<Register>, MemoryDomain::Registers> m_registers;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,19 +25,18 @@ StringDataPtr StringData::Registry::intern(StringView str)
|
||||||
{
|
{
|
||||||
auto it = m_strings.find(str);
|
auto it = m_strings.find(str);
|
||||||
if (it != m_strings.end())
|
if (it != m_strings.end())
|
||||||
return StringDataPtr{it->second};
|
return StringDataPtr{it->value};
|
||||||
|
|
||||||
auto data = StringData::create(str);
|
auto data = StringData::create(str);
|
||||||
data->refcount |= interned_flag;
|
data->refcount |= interned_flag;
|
||||||
m_strings.emplace(data->strview(), data.get());
|
m_strings.insert({data->strview(), data.get()});
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringData::Registry::remove(StringView str)
|
void StringData::Registry::remove(StringView str)
|
||||||
{
|
{
|
||||||
auto it = m_strings.find(str);
|
kak_assert(m_strings.contains(str));
|
||||||
kak_assert(it != m_strings.end());
|
m_strings.unordered_remove(str);
|
||||||
m_strings.erase(it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void StringData::Registry::debug_stats() const
|
void StringData::Registry::debug_stats() const
|
||||||
|
@ -48,8 +47,8 @@ void StringData::Registry::debug_stats() const
|
||||||
size_t count = m_strings.size();
|
size_t count = m_strings.size();
|
||||||
for (auto& st : m_strings)
|
for (auto& st : m_strings)
|
||||||
{
|
{
|
||||||
total_refcount += st.second->refcount - 1;
|
total_refcount += st.value->refcount - 1;
|
||||||
total_size += (int)st.second->length;
|
total_size += (int)st.value->length;
|
||||||
}
|
}
|
||||||
write_to_debug_buffer(format(" data size: {}, mean: {}", total_size, (float)total_size/count));
|
write_to_debug_buffer(format(" data size: {}, mean: {}", total_size, (float)total_size/count));
|
||||||
write_to_debug_buffer(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count));
|
write_to_debug_buffer(format(" refcounts: {}, mean: {}", total_refcount, (float)total_refcount/count));
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "string.hh"
|
#include "string.hh"
|
||||||
#include "ref_ptr.hh"
|
#include "ref_ptr.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
|
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public:
|
||||||
void remove(StringView str);
|
void remove(StringView str);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
UnorderedMap<StringView, StringData*, MemoryDomain::SharedString> m_strings;
|
HashMap<StringView, StringData*, MemoryDomain::SharedString> m_strings;
|
||||||
};
|
};
|
||||||
|
|
||||||
static Ptr create(ArrayView<const StringView> strs);
|
static Ptr create(ArrayView<const StringView> strs);
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
#ifndef unordered_map_hh_INCLUDED
|
|
||||||
#define unordered_map_hh_INCLUDED
|
|
||||||
|
|
||||||
#include "hash.hh"
|
|
||||||
#include "memory.hh"
|
|
||||||
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <unordered_set>
|
|
||||||
|
|
||||||
namespace Kakoune
|
|
||||||
{
|
|
||||||
|
|
||||||
template<typename Key, typename Value, MemoryDomain domain = TypeDomain<Key>::domain()>
|
|
||||||
using UnorderedMap = std::unordered_map<Key, Value, Hash<Key>, std::equal_to<Key>,
|
|
||||||
Allocator<std::pair<const Key, Value>, domain>>;
|
|
||||||
|
|
||||||
template<typename Key, MemoryDomain domain = TypeDomain<Key>::domain()>
|
|
||||||
using UnorderedSet = std::unordered_set<Key, Hash<Key>, std::equal_to<Key>,
|
|
||||||
Allocator<Key, domain>>;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // unordered_map_hh_INCLUDED
|
|
|
@ -1,7 +1,7 @@
|
||||||
#ifndef value_hh_INCLUDED
|
#ifndef value_hh_INCLUDED
|
||||||
#define value_hh_INCLUDED
|
#define value_hh_INCLUDED
|
||||||
|
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
#include "units.hh"
|
#include "units.hh"
|
||||||
|
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
@ -76,7 +76,7 @@ inline ValueId get_free_value_id()
|
||||||
return (ValueId)(next++);
|
return (ValueId)(next++);
|
||||||
}
|
}
|
||||||
|
|
||||||
using ValueMap = UnorderedMap<ValueId, Value, MemoryDomain::Values>;
|
using ValueMap = HashMap<ValueId, Value, MemoryDomain::Values>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ void WordDB::add_words(StringView line)
|
||||||
{
|
{
|
||||||
auto it = m_words.find(w);
|
auto it = m_words.find(w);
|
||||||
if (it != m_words.end())
|
if (it != m_words.end())
|
||||||
++it->second.refcount;
|
++it->value.refcount;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
auto word = intern(w);
|
auto word = intern(w);
|
||||||
|
@ -60,9 +60,9 @@ void WordDB::remove_words(StringView line)
|
||||||
for (auto& w : get_words(line, get_extra_word_chars(*m_buffer)))
|
for (auto& w : get_words(line, get_extra_word_chars(*m_buffer)))
|
||||||
{
|
{
|
||||||
auto it = m_words.find(w);
|
auto it = m_words.find(w);
|
||||||
kak_assert(it != m_words.end() and it->second.refcount > 0);
|
kak_assert(it != m_words.end() and it->value.refcount > 0);
|
||||||
if (--it->second.refcount == 0)
|
if (--it->value.refcount == 0)
|
||||||
m_words.erase(it);
|
m_words.unordered_remove(it->key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ int WordDB::get_word_occurences(StringView word) const
|
||||||
{
|
{
|
||||||
auto it = m_words.find(word);
|
auto it = m_words.find(word);
|
||||||
if (it != m_words.end())
|
if (it != m_words.end())
|
||||||
return it->second.refcount;
|
return it->value.refcount;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ RankedMatchList WordDB::find_matching(StringView query)
|
||||||
RankedMatchList res;
|
RankedMatchList res;
|
||||||
for (auto&& word : m_words)
|
for (auto&& word : m_words)
|
||||||
{
|
{
|
||||||
if (RankedMatch match{word.first, word.second.letters, query, letters})
|
if (RankedMatch match{word.key, word.value.letters, query, letters})
|
||||||
res.push_back(match);
|
res.push_back(match);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include "buffer.hh"
|
#include "buffer.hh"
|
||||||
#include "shared_string.hh"
|
#include "shared_string.hh"
|
||||||
#include "unordered_map.hh"
|
#include "hash_map.hh"
|
||||||
#include "vector.hh"
|
#include "vector.hh"
|
||||||
#include "ranked_match.hh"
|
#include "ranked_match.hh"
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ private:
|
||||||
UsedLetters letters;
|
UsedLetters letters;
|
||||||
int refcount;
|
int refcount;
|
||||||
};
|
};
|
||||||
using WordToInfo = UnorderedMap<StringView, WordInfo, MemoryDomain::WordDB>;
|
using WordToInfo = HashMap<StringView, WordInfo, MemoryDomain::WordDB>;
|
||||||
using Lines = Vector<StringDataPtr, MemoryDomain::WordDB>;
|
using Lines = Vector<StringDataPtr, MemoryDomain::WordDB>;
|
||||||
|
|
||||||
SafePtr<const Buffer> m_buffer;
|
SafePtr<const Buffer> m_buffer;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user