HighlighterRegistry: use idvaluemap to store factories

This commit is contained in:
Maxime Coste 2011-12-02 14:22:51 +00:00
parent 4252e0d610
commit 8e06e168d9
2 changed files with 5 additions and 11 deletions

View File

@ -14,8 +14,8 @@ struct factory_not_found : public runtime_error
void HighlighterRegistry::register_factory(const std::string& name,
const HighlighterFactory& factory)
{
assert(m_factories.find(name) == m_factories.end());
m_factories[name] = factory;
assert(not m_factories.contains(name));
m_factories.append(std::make_pair(name, factory));
}
void HighlighterRegistry::add_highlighter_to_window(Window& window,
@ -32,14 +32,7 @@ void HighlighterRegistry::add_highlighter_to_window(Window& window,
CandidateList HighlighterRegistry::complete_highlighter(const std::string& prefix,
size_t cursor_pos)
{
std::string real_prefix = prefix.substr(0, cursor_pos);
CandidateList result;
for (auto& highlighter : m_factories)
{
if (highlighter.first.substr(0, real_prefix.length()) == real_prefix)
result.push_back(highlighter.first);
}
return result;
return m_factories.complete_id<str_to_str>(prefix, cursor_pos);
}
}

View File

@ -7,6 +7,7 @@
#include "highlighter.hh"
#include "utils.hh"
#include "completion.hh"
#include "idvaluemap.hh"
namespace Kakoune
{
@ -32,7 +33,7 @@ public:
size_t cursor_pos);
private:
std::unordered_map<std::string, HighlighterFactory> m_factories;
idvaluemap<std::string, HighlighterFactory> m_factories;
};
}