Reduce virtual calls for get_arity

Saves compiled code size and some minor runtime differences
This commit is contained in:
Jason Turner
2014-11-01 18:40:42 -06:00
parent 87cee688a8
commit dd12785b72
3 changed files with 24 additions and 56 deletions

View File

@@ -257,7 +257,7 @@ namespace chaiscript
{
public:
Dispatch_Function(std::vector<Proxy_Function> t_funcs)
: Proxy_Function_Base(build_type_infos(t_funcs)),
: Proxy_Function_Base(build_type_infos(t_funcs), calculate_arity(t_funcs)),
m_funcs(std::move(t_funcs))
{
}
@@ -280,15 +280,15 @@ namespace chaiscript
}
virtual int get_arity() const CHAISCRIPT_OVERRIDE
static int calculate_arity(const std::vector<Proxy_Function> &t_funcs)
{
if (m_funcs.empty()) {
if (t_funcs.empty()) {
return -1;
}
const auto arity = m_funcs.front()->get_arity();
const auto arity = t_funcs.front()->get_arity();
for (const auto &func : m_funcs)
for (const auto &func : t_funcs)
{
if (arity != func->get_arity())
{