1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-05-23 10:17:44 +00:00

Update ExdData.h

Implemente cache for Linux build
This commit is contained in:
AriAvery 2023-04-23 20:03:19 +02:00
parent 22a51062c2
commit 8ff1e9ecba

View file

@ -55,17 +55,41 @@ template< typename T >
std::string ExdData::getSheetName() std::string ExdData::getSheetName()
{ {
auto origName = std::string( typeid( T ).name() ); auto origName = std::string( typeid( T ).name() );
#if _WIN32 #if _WIN32
auto pos = origName.find_last_of( ':' ); auto pos = origName.find_last_of( ':' );
return pos != std::string::npos ? origName.substr( pos + 1 ) : "[something_fucking_died]"; if( pos != std::string::npos )
{
return origName.substr( pos + 1 );
}
else
{
throw std::runtime_error( "Failed to extract the sheet name" );
}
#else #else
static std::unordered_map< std::type_index, std::string > demangle_cache;
auto type = typeid( T );
auto it = demangle_cache.find( type );
if( it != demangle_cache.end() )
{
return it->second;
}
int status = -4; int status = -4;
char* res = abi::__cxa_demangle( origName.c_str(), nullptr, nullptr, &status ); char* res = abi::__cxa_demangle( origName.c_str(), nullptr, nullptr, &status );
std::string demangledName = ( status == 0 ) ? res : origName; if( status == 0 )
{
std::string demangledName = res;
auto pos = demangledName.find_last_of( ':' ); auto pos = demangledName.find_last_of( ':' );
if( pos != std::string::npos ) demangledName = demangledName.substr( pos + 1 ); if( pos != std::string::npos ) demangledName = demangledName.substr( pos + 1 );
demangle_cache[ type ] = demangledName;
free( res ); free( res );
return demangledName; return demangledName;
}
else
{
throw std::runtime_error( "Failed to demangle the type name" );
}
#endif #endif
} }