mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-05-23 02:07:45 +00:00
Update ExdData.h
Implemente cache for Linux build
This commit is contained in:
parent
22a51062c2
commit
8ff1e9ecba
1 changed files with 31 additions and 7 deletions
|
@ -51,21 +51,45 @@ namespace Sapphire::Data
|
||||||
std::shared_ptr< xiv::exd::ExdData > m_exd_data;
|
std::shared_ptr< xiv::exd::ExdData > m_exd_data;
|
||||||
};
|
};
|
||||||
|
|
||||||
template< typename T >
|
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 )
|
||||||
auto pos = demangledName.find_last_of( ':' );
|
{
|
||||||
if( pos != std::string::npos ) demangledName = demangledName.substr( pos + 1 );
|
std::string demangledName = res;
|
||||||
free( res );
|
auto pos = demangledName.find_last_of( ':' );
|
||||||
return demangledName;
|
if( pos != std::string::npos ) demangledName = demangledName.substr( pos + 1 );
|
||||||
|
demangle_cache[ type ] = demangledName;
|
||||||
|
free( res );
|
||||||
|
return demangledName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error( "Failed to demangle the type name" );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue