From fbe82bf94d7a28af7a73b69522766d8a1e03ecb7 Mon Sep 17 00:00:00 2001 From: Wenzel Jakob Date: Tue, 28 Jul 2015 16:12:29 +0200 Subject: [PATCH] code size reduction --- include/pybind/typeid.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/include/pybind/typeid.h b/include/pybind/typeid.h index c452c3f5..73ee8ec3 100644 --- a/include/pybind/typeid.h +++ b/include/pybind/typeid.h @@ -26,23 +26,27 @@ inline void erase_all(std::string &string, const std::string &search) { string.erase(pos, search.length()); } } -NAMESPACE_END(detail) -/// Return a string representation of a C++ type -template static std::string type_id() { - std::string name(typeid(T).name()); - #if defined(__GNUG__) - int status = 0; - std::unique_ptr res { - abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free }; - if (status == 0) - name = res.get(); +inline void clean_type_id(std::string &name) { +#if defined(__GNUG__) + int status = 0; + std::unique_ptr res { + abi::__cxa_demangle(name.c_str(), nullptr, nullptr, &status), std::free }; + if (status == 0) + name = res.get(); #else detail::erase_all(name, "class "); detail::erase_all(name, "struct "); detail::erase_all(name, "enum "); #endif detail::erase_all(name, "pybind::"); +} +NAMESPACE_END(detail) + +/// Return a string representation of a C++ type +template static std::string type_id() { + std::string name(typeid(T).name()); + detail::clean_type_id(name); return name; }