Use StringView in FunctionGroup and FunctionRegistry

This commit is contained in:
Maxime Coste 2014-04-21 10:50:09 +01:00
parent a1ec45d91a
commit 8beda67fae
2 changed files with 8 additions and 8 deletions

View File

@ -33,23 +33,23 @@ public:
m_functions.append(std::forward<FunctionAndId>(function));
}
void remove(const String& id)
void remove(StringView id)
{
m_functions.remove(id);
}
FunctionGroup& get_group(const String& path, Codepoint path_separator = 0)
FunctionGroup& get_group(StringView path, Codepoint path_separator = 0)
{
auto sep_it = std::find(path.begin(), path.end(), path_separator);
String id(path.begin(), sep_it);
StringView id(path.begin(), sep_it);
auto it = m_functions.find(id);
if (it == m_functions.end())
throw group_not_found("no such id: " + id);
throw group_not_found("no such id: "_str + id);
FunctionGroup* group = it->second.template target<FunctionGroup>();
if (not group)
throw group_not_found("not a group: " + id);
throw group_not_found("not a group: "_str + id);
if (sep_it != path.end())
return group->get_group(String(sep_it+1, path.end()), path_separator);
return group->get_group(StringView(sep_it+1, path.end()), path_separator);
else
return *group;
}

View File

@ -18,13 +18,13 @@ template<typename FunctionType>
class FunctionRegistry
{
public:
void register_func(const String& name, const FunctionType& function)
void register_func(StringView name, const FunctionType& function)
{
kak_assert(not m_functions.contains(name));
m_functions.append(std::make_pair(name, function));
}
const FunctionType& operator[](const String& name) const
const FunctionType& operator[](StringView name) const
{
auto it = m_functions.find(name);
if (it == m_functions.end())