Move code that doesn't need to be in a template, out of the template, to reduce duplicated binary code

This commit is contained in:
Brent Davis 2020-06-18 17:08:49 -05:00 committed by The Phantom Derpstorm
parent 1ce551e9ee
commit 37c61eb16b
3 changed files with 45 additions and 27 deletions

View File

@ -1,4 +1,4 @@
// sol3
// sol3
// The MIT License (MIT)
@ -49,11 +49,9 @@ namespace detail {
#if defined(__GNUC__) || defined(__clang__)
template <typename T, class seperator_mark = int>
inline std::string ctti_get_type_name() {
inline std::string ctti_get_type_name_from_sig(std::string name) {
// cardinal sins from MINGW
using namespace std;
std::string name = __PRETTY_FUNCTION__;
std::size_t start = name.find_first_of('[');
start = name.find_first_of('=', start);
std::size_t end = name.find_last_of(']');
@ -83,10 +81,13 @@ namespace detail {
return name;
}
template <typename T, class seperator_mark = int>
inline std::string ctti_get_type_name() {
return ctti_get_type_name_from_sig(__PRETTY_FUNCTION__);
}
#elif defined(_MSC_VER)
template <typename T>
std::string ctti_get_type_name() {
std::string name = __FUNCSIG__;
inline std::string ctti_get_type_name_from_sig(std::string name) {
std::size_t start = name.find("get_type_name");
if (start == std::string::npos)
start = 0;
@ -117,6 +118,11 @@ namespace detail {
return name;
}
template <typename T>
std::string ctti_get_type_name() {
return ctti_get_type_name_from_sig(__FUNCSIG__);
}
#else
#error Compiler not supported for demangling
#endif // compilers
@ -127,9 +133,7 @@ namespace detail {
return realname;
}
template <typename T>
std::string short_demangle_once() {
std::string realname = ctti_get_type_name<T>();
inline std::string short_demangle_from_type_name(std::string realname) {
// This isn't the most complete but it'll do for now...?
static const std::array<std::string, 10> ops = {{"operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*"}};
int level = 0;
@ -165,6 +169,12 @@ namespace detail {
return realname;
}
template <typename T>
std::string short_demangle_once() {
std::string realname = ctti_get_type_name<T>();
return short_demangle_from_type_name(realname);
}
template <typename T>
const std::string& demangle() {
static const std::string d = demangle_once<T>();
@ -176,7 +186,6 @@ namespace detail {
static const std::string d = short_demangle_once<T>();
return d;
}
}
} // namespace sol::detail
}} // namespace sol::detail
#endif // SOL_DEMANGLE_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2020-06-06 16:05:17.750133 UTC
// This header was generated with sol v3.2.1 (revision e09d2ff)
// Generated 2020-06-18 21:54:34.473478 UTC
// This header was generated with sol v3.2.1 (revision 62a831cd)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_FORWARD_HPP

View File

@ -20,8 +20,8 @@
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// This file was generated with a script.
// Generated 2020-06-06 16:05:12.150007 UTC
// This header was generated with sol v3.2.1 (revision e09d2ff)
// Generated 2020-06-18 21:54:34.347814 UTC
// This header was generated with sol v3.2.1 (revision 62a831cd)
// https://github.com/ThePhD/sol2
#ifndef SOL_SINGLE_INCLUDE_HPP
@ -7620,11 +7620,9 @@ namespace detail {
"`anonymous namespace'" } };
#if defined(__GNUC__) || defined(__clang__)
template <typename T, class seperator_mark = int>
inline std::string ctti_get_type_name() {
inline std::string ctti_get_type_name_from_sig(std::string name) {
// cardinal sins from MINGW
using namespace std;
std::string name = __PRETTY_FUNCTION__;
std::size_t start = name.find_first_of('[');
start = name.find_first_of('=', start);
std::size_t end = name.find_last_of(']');
@ -7654,10 +7652,13 @@ namespace detail {
return name;
}
template <typename T, class seperator_mark = int>
inline std::string ctti_get_type_name() {
return ctti_get_type_name_from_sig(__PRETTY_FUNCTION__);
}
#elif defined(_MSC_VER)
template <typename T>
std::string ctti_get_type_name() {
std::string name = __FUNCSIG__;
inline std::string ctti_get_type_name_from_sig(std::string name) {
std::size_t start = name.find("get_type_name");
if (start == std::string::npos)
start = 0;
@ -7688,6 +7689,11 @@ namespace detail {
return name;
}
template <typename T>
std::string ctti_get_type_name() {
return ctti_get_type_name_from_sig(__FUNCSIG__);
}
#else
#error Compiler not supported for demangling
#endif // compilers
@ -7698,9 +7704,7 @@ namespace detail {
return realname;
}
template <typename T>
std::string short_demangle_once() {
std::string realname = ctti_get_type_name<T>();
inline std::string short_demangle_from_type_name(std::string realname) {
// This isn't the most complete but it'll do for now...?
static const std::array<std::string, 10> ops = {{"operator<", "operator<<", "operator<<=", "operator<=", "operator>", "operator>>", "operator>>=", "operator>=", "operator->", "operator->*"}};
int level = 0;
@ -7736,6 +7740,12 @@ namespace detail {
return realname;
}
template <typename T>
std::string short_demangle_once() {
std::string realname = ctti_get_type_name<T>();
return short_demangle_from_type_name(realname);
}
template <typename T>
const std::string& demangle() {
static const std::string d = demangle_once<T>();
@ -7747,8 +7757,7 @@ namespace detail {
static const std::string d = short_demangle_once<T>();
return d;
}
}
} // namespace sol::detail
}} // namespace sol::detail
// end of sol/demangle.hpp