Drastically reduce the number of exceptions thrown at runtime (cannot completely eliminate them all, it's the nature of doing what we are doing with making a runtime interface to a compiled system like we are).
profile.chai should see something like a reduction from 35,000 exceptions to about 100.
This commit is contained in:
@@ -71,11 +71,11 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &f) const
|
virtual bool operator==(const Proxy_Function_Base &f) const
|
||||||
{
|
{
|
||||||
try
|
const Dynamic_Object_Function *df = dynamic_cast<const Dynamic_Object_Function *>(&f);
|
||||||
|
if (df)
|
||||||
{
|
{
|
||||||
const Dynamic_Object_Function &df = dynamic_cast<const Dynamic_Object_Function &>(f);
|
return df->m_type_name == m_type_name && (*df->m_func) == (*m_func);
|
||||||
return df.m_type_name == m_type_name && (*df.m_func) == (*m_func);
|
} else {
|
||||||
} catch (const std::bad_cast &) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,23 +110,42 @@ namespace chaiscript
|
|||||||
return m_func->annotation();
|
return m_func->annotation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool compare_first_type(const Boxed_Value &bv) const
|
||||||
|
{
|
||||||
|
return dynamic_object_typename_match(bv, m_type_name, m_ti);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool dynamic_object_typename_match(const Boxed_Value &bv, const std::string &name,
|
||||||
|
const boost::optional<Type_Info> &ti)
|
||||||
|
{
|
||||||
|
static Type_Info doti = user_type<Dynamic_Object>();
|
||||||
|
if (bv.get_type_info().bare_equal(doti))
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bv);
|
||||||
|
return name == "Dynamic_Object" || d.get_type_name() == name;
|
||||||
|
} catch (const std::bad_cast &) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (ti)
|
||||||
|
{
|
||||||
|
return bv.get_type_info().bare_equal(*ti);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
|
static bool dynamic_object_typename_match(const std::vector<Boxed_Value> &bvs, const std::string &name,
|
||||||
const boost::optional<Type_Info> &ti)
|
const boost::optional<Type_Info> &ti)
|
||||||
{
|
{
|
||||||
if (bvs.size() > 0)
|
if (bvs.size() > 0)
|
||||||
{
|
{
|
||||||
try {
|
return dynamic_object_typename_match(bvs[0], name, ti);
|
||||||
const Dynamic_Object &d = boxed_cast<const Dynamic_Object &>(bvs[0]);
|
|
||||||
return name == "Dynamic_Object" || d.get_type_name() == name;
|
|
||||||
} catch (const std::bad_cast &) {
|
|
||||||
if (ti)
|
|
||||||
{
|
|
||||||
return bvs[0].get_type_info().bare_equal(*ti);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -175,11 +194,11 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &f) const
|
virtual bool operator==(const Proxy_Function_Base &f) const
|
||||||
{
|
{
|
||||||
try
|
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
|
||||||
|
if (dc)
|
||||||
{
|
{
|
||||||
const Dynamic_Object_Constructor &dc = dynamic_cast<const Dynamic_Object_Constructor&>(f);
|
return dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
||||||
return dc.m_type_name == m_type_name && (*dc.m_func) == (*m_func);
|
} else {
|
||||||
} catch (const std::bad_cast &) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -72,6 +72,7 @@ namespace chaiscript
|
|||||||
virtual bool operator==(const Proxy_Function_Base &) const = 0;
|
virtual bool operator==(const Proxy_Function_Base &) const = 0;
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals) const = 0;
|
virtual bool call_match(const std::vector<Boxed_Value> &vals) const = 0;
|
||||||
|
|
||||||
|
|
||||||
//! Return true if the function is a possible match
|
//! Return true if the function is a possible match
|
||||||
//! to the passed in values
|
//! to the passed in values
|
||||||
bool filter(const std::vector<Boxed_Value> &vals) const
|
bool filter(const std::vector<Boxed_Value> &vals) const
|
||||||
@@ -86,26 +87,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
const std::vector<Type_Info> &types = get_param_types();
|
return compare_first_type(vals[0]);
|
||||||
|
|
||||||
if (types.size() < 2)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Type_Info &ti = types[1];
|
|
||||||
|
|
||||||
|
|
||||||
if (ti.is_undef() || vals[0].get_type_info().is_undef()
|
|
||||||
|| ti.bare_equal(user_type<Boxed_Value>())
|
|
||||||
|| ti.bare_equal(user_type<Boxed_POD_Value>())
|
|
||||||
|| ti.bare_equal(vals[0].get_type_info())
|
|
||||||
|| dynamic_cast_converts(ti, vals[0].get_type_info()) )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
@@ -122,6 +104,31 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual bool compare_first_type(const Boxed_Value &bv) const
|
||||||
|
{
|
||||||
|
const std::vector<Type_Info> &types = get_param_types();
|
||||||
|
|
||||||
|
if (types.size() < 2)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const Type_Info &ti = types[1];
|
||||||
|
if (ti.is_undef()
|
||||||
|
|| ti.bare_equal(user_type<Boxed_Value>())
|
||||||
|
|| (!bv.get_type_info().is_undef()
|
||||||
|
&& (ti.bare_equal(user_type<Boxed_POD_Value>())
|
||||||
|
|| ti.bare_equal(bv.get_type_info())
|
||||||
|
|| dynamic_cast_converts(ti, bv.get_type_info())
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs) const
|
bool compare_types(const std::vector<Type_Info> &tis, const std::vector<Boxed_Value> &bvs) const
|
||||||
{
|
{
|
||||||
if (tis.size() - 1 != bvs.size())
|
if (tis.size() - 1 != bvs.size())
|
||||||
@@ -368,12 +375,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &t_func) const
|
virtual bool operator==(const Proxy_Function_Base &t_func) const
|
||||||
{
|
{
|
||||||
try {
|
const Proxy_Function_Impl *pimpl = dynamic_cast<const Proxy_Function_Impl<Func> *>(&t_func);
|
||||||
dynamic_cast<const Proxy_Function_Impl<Func> &>(t_func);
|
return pimpl != 0;
|
||||||
return true;
|
|
||||||
} catch (const std::bad_cast &) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value operator()(const std::vector<Boxed_Value> ¶ms) const
|
virtual Boxed_Value operator()(const std::vector<Boxed_Value> ¶ms) const
|
||||||
@@ -424,11 +427,11 @@ namespace chaiscript
|
|||||||
|
|
||||||
virtual bool operator==(const Proxy_Function_Base &t_func) const
|
virtual bool operator==(const Proxy_Function_Base &t_func) const
|
||||||
{
|
{
|
||||||
try {
|
const Attribute_Access<T, Class> * aa
|
||||||
const Attribute_Access<T, Class> &aa
|
= dynamic_cast<const Attribute_Access<T, Class> *>(&t_func);
|
||||||
= dynamic_cast<const Attribute_Access<T, Class> &>(t_func);
|
if (aa) {
|
||||||
return m_attr == aa.m_attr;
|
return m_attr == aa->m_attr;
|
||||||
} catch (const std::bad_cast &) {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user