Beautiful Capi is a tool which automates the creation of compiler-independent and binary compatible C++ libraries across different C++ compilers
GNU General Public License v3.0
33
stars
4
forks
source link
Optimize conversion from c to wrap #76
Open
PetrPPetrov opened 6 years ago
Right now, if use ternary operation ? : the C function is called twice:
inline std::string STL::BasicString::CStr() const
{
exception_info_t cur_exception_info;
std::string result(std::string(stl_basic_string_char_cstr_const(&cur_exception_info, GetRawPointer()) ? stl_basic_string_char_cstr_const(&cur_exception_info, GetRawPointer()) : ""));
STL::check_and_throw_exception(cur_exception_info.code, cur_exception_info.object_pointer);
return result;
}
however, better to generate something like that:
inline std::string STL::BasicString::CStr() const
{
exception_info_t cur_exception_info;
const char* c_result = stl_basic_string_char_cstr_const(&cur_exception_info, GetRawPointer());
std::string result(std::string(c_result ? c_result : ""));
STL::check_and_throw_exception(cur_exception_info.code, cur_exception_info.object_pointer);
return result;
}