Use StringView in FunctionGroup and FunctionRegistry
This commit is contained in:
parent
a1ec45d91a
commit
8beda67fae
|
@ -33,23 +33,23 @@ public:
|
||||||
|
|
||||||
m_functions.append(std::forward<FunctionAndId>(function));
|
m_functions.append(std::forward<FunctionAndId>(function));
|
||||||
}
|
}
|
||||||
void remove(const String& id)
|
void remove(StringView id)
|
||||||
{
|
{
|
||||||
m_functions.remove(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);
|
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);
|
auto it = m_functions.find(id);
|
||||||
if (it == m_functions.end())
|
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>();
|
FunctionGroup* group = it->second.template target<FunctionGroup>();
|
||||||
if (not group)
|
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())
|
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
|
else
|
||||||
return *group;
|
return *group;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,13 +18,13 @@ template<typename FunctionType>
|
||||||
class FunctionRegistry
|
class FunctionRegistry
|
||||||
{
|
{
|
||||||
public:
|
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));
|
kak_assert(not m_functions.contains(name));
|
||||||
m_functions.append(std::make_pair(name, function));
|
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);
|
auto it = m_functions.find(name);
|
||||||
if (it == m_functions.end())
|
if (it == m_functions.end())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user