Optimize dispatch for perfect match case

This commit is contained in:
Jason Turner
2016-04-20 07:26:42 -06:00
parent 06b2893bfb
commit 647f8842fd

View File

@@ -181,11 +181,9 @@ namespace chaiscript
//! to the passed in values
bool filter(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const
{
assert(m_arity == -1 || (m_arity > 1 && vals.size() == m_arity));
if (m_arity < 0)
{
return true;
} else if (static_cast<size_t>(m_arity) == vals.size()) {
if (m_arity == 0)
{
return true;
} else if (m_arity > 1) {
@@ -193,9 +191,6 @@ namespace chaiscript
} else {
return compare_type_to_param(m_types[1], vals[0], t_conversions);
}
} else {
return false;
}
}
/// \returns the number of arguments the function takes or -1 if it is variadic
@@ -887,7 +882,7 @@ namespace chaiscript
for (const auto &func : ordered_funcs )
{
try {
if (func.first == i && func.second->filter(plist, t_conversions))
if (func.first == i && (i == 0 || func.second->filter(plist, t_conversions)))
{
return (*(func.second))(plist, t_conversions);
}