Reduce copies of UDTs

This commit is contained in:
Jason Turner
2015-04-07 10:23:43 -06:00
parent 962bdf4b3c
commit 79181fe41e
3 changed files with 20 additions and 22 deletions

View File

@@ -65,21 +65,11 @@ namespace chaiscript
typedef const Result * Result_Type;
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
{
if (ob.is_ref())
if (ob.get_type_info().bare_equal_type_info(typeid(Result)))
{
if (!ob.get_type_info().is_const())
{
return &(ob.get().cast<std::reference_wrapper<Result> >()).get();
} else {
return &(ob.get().cast<std::reference_wrapper<const Result> >()).get();
}
return static_cast<const Result *>(throw_if_null(ob.get_const_ptr()));
} else {
if (!ob.get_type_info().is_const())
{
return (ob.get().cast<std::shared_ptr<Result> >()).get();
} else {
return (ob.get().cast<std::shared_ptr<const Result> >()).get();
}
throw chaiscript::detail::exception::bad_any_cast();
}
}
};
@@ -91,11 +81,11 @@ namespace chaiscript
typedef Result * Result_Type;
static Result_Type cast(const Boxed_Value &ob, const Type_Conversions *)
{
if (ob.is_ref())
if (!ob.get_type_info().is_const() && ob.get_type_info().bare_equal_type_info(typeid(Result)))
{
return &(ob.get().cast<std::reference_wrapper<Result> >()).get();
return static_cast<Result *>(throw_if_null(ob.get_ptr()));
} else {
return (ob.get().cast<std::shared_ptr<Result> >()).get();
throw chaiscript::detail::exception::bad_any_cast();
}
}
};