Apply some IIFE to reduce copies
This commit is contained in:
@@ -119,24 +119,27 @@ namespace chaiscript
|
||||
// Dynamic cast out the contained boxed value, which we know is the type we want
|
||||
if (t_from.is_const())
|
||||
{
|
||||
std::shared_ptr<const To> data
|
||||
= std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr));
|
||||
if (!data)
|
||||
return Boxed_Value(
|
||||
[&]()->std::shared_ptr<const To>{
|
||||
if (auto data = std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
||||
{
|
||||
throw std::bad_cast();
|
||||
}
|
||||
|
||||
return Boxed_Value(data);
|
||||
return data;
|
||||
} else {
|
||||
std::shared_ptr<To> data
|
||||
= std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr));
|
||||
|
||||
if (!data)
|
||||
{
|
||||
throw std::bad_cast();
|
||||
}
|
||||
|
||||
return Boxed_Value(data);
|
||||
}()
|
||||
);
|
||||
} else {
|
||||
return Boxed_Value(
|
||||
[&]()->std::shared_ptr<To>{
|
||||
if (auto data = std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
||||
{
|
||||
return data;
|
||||
} else {
|
||||
throw std::bad_cast();
|
||||
}
|
||||
}()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Pull the reference out of the contained boxed value, which we know is the type we want
|
||||
@@ -439,9 +442,7 @@ namespace chaiscript
|
||||
static_assert(std::is_convertible<From, To>::value, "Types are not automatically convertible");
|
||||
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
|
||||
// not even attempting to call boxed_cast so that we don't get caught in some call recursion
|
||||
auto &&from = detail::Cast_Helper<From>::cast(t_bv, nullptr);
|
||||
To to(from);
|
||||
return chaiscript::Boxed_Value(to);
|
||||
return chaiscript::Boxed_Value(To(detail::Cast_Helper<From>::cast(t_bv, nullptr)));
|
||||
};
|
||||
|
||||
return std::make_shared<detail::Type_Conversion_Impl<decltype(func)>>(user_type<From>(), user_type<To>(), func);
|
||||
|
@@ -617,14 +617,16 @@ namespace chaiscript
|
||||
}
|
||||
|
||||
|
||||
size_t size = sizeof(int) * 8;
|
||||
|
||||
const size_t size = [&](){
|
||||
if (longlong_)
|
||||
{
|
||||
size = sizeof(int64_t) * 8;
|
||||
return sizeof(int64_t) * 8;
|
||||
} else if (long_) {
|
||||
size = sizeof(long) * 8;
|
||||
return sizeof(long) * 8;
|
||||
} else {
|
||||
return sizeof(int) * 8;
|
||||
}
|
||||
}();
|
||||
|
||||
if ( (u >> (size - 1)) > 0)
|
||||
{
|
||||
@@ -794,17 +796,19 @@ namespace chaiscript
|
||||
return Id_();
|
||||
} else {
|
||||
const auto start = m_input_pos;
|
||||
const int prev_col = m_col;
|
||||
const int prev_line = m_line;
|
||||
const auto prev_col = m_col;
|
||||
const auto prev_line = m_line;
|
||||
if (Id_()) {
|
||||
std::string match;
|
||||
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(
|
||||
[&](){
|
||||
if (*start == '`') {
|
||||
//Id Literal
|
||||
match = std::string(start+1, m_input_pos-1);
|
||||
return std::string(start+1, m_input_pos-1);
|
||||
} else {
|
||||
match = std::string(start, m_input_pos);
|
||||
return std::string(start, m_input_pos);
|
||||
}
|
||||
m_match_stack.push_back(std::make_shared<eval::Id_AST_Node>(std::move(match), m_filename, prev_line, prev_col, m_line, m_col));
|
||||
}(),
|
||||
m_filename, prev_line, prev_col, m_line, m_col));
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user