diff --git a/profiler/src/ConnectionHistory.cpp b/profiler/src/ConnectionHistory.cpp index b4bb378d..eddad3fb 100644 --- a/profiler/src/ConnectionHistory.cpp +++ b/profiler/src/ConnectionHistory.cpp @@ -65,17 +65,16 @@ void ConnectionHistory::Rebuild() std::swap( m_connHistVec, vec ); } -void ConnectionHistory::Count( const char* name ) +void ConnectionHistory::Count( const std::string& name ) { - std::string addr( name ); - auto it = m_connHistMap.find( addr ); + auto it = m_connHistMap.find( name ); if( it != m_connHistMap.end() ) { it->second++; } else { - m_connHistMap.emplace( std::move( addr ), 1 ); + m_connHistMap.emplace( name, 1 ); } Rebuild(); } diff --git a/profiler/src/ConnectionHistory.hpp b/profiler/src/ConnectionHistory.hpp index 1a5c823c..e3c4f605 100644 --- a/profiler/src/ConnectionHistory.hpp +++ b/profiler/src/ConnectionHistory.hpp @@ -14,7 +14,7 @@ public: const std::string& Name( size_t idx ) const { return m_connHistVec[idx]->first; } - void Count( const char* name ); + void Count( const std::string& name ); void Erase( size_t idx ); bool empty() const { return m_connHistVec.empty(); } diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 68b8c131..d5ba6be8 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -967,20 +967,29 @@ static void DrawContents() connectClicked |= ImGui::Button( ICON_FA_WIFI " Connect" ); if( connectClicked && *addr && !loadThread.joinable() ) { - connHist->Count( addr ); + auto aptr = addr; + while( *aptr == ' ' || *aptr == '\t' ) aptr++; + auto aend = aptr; + while( *aend && *aend != ' ' && *aend != '\t' ) aend++; - const auto addrLen = strlen( addr ); - auto ptr = addr + addrLen - 1; - while( ptr > addr && *ptr != ':' ) ptr--; - if( *ptr == ':' ) + if( aptr != aend ) { - std::string addrPart = std::string( addr, ptr ); - uint16_t portPart = (uint16_t)atoi( ptr+1 ); - view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements ); - } - else - { - view = std::make_unique( RunOnMainThread, addr, port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements ); + std::string address( aptr, aend ); + connHist->Count( address ); + + auto adata = address.data(); + auto ptr = adata + address.size() - 1; + while( ptr > adata && *ptr != ':' ) ptr--; + if( *ptr == ':' ) + { + std::string addrPart = std::string( adata, ptr ); + uint16_t portPart = (uint16_t)atoi( ptr+1 ); + view = std::make_unique( RunOnMainThread, addrPart.c_str(), portPart, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements ); + } + else + { + view = std::make_unique( RunOnMainThread, address.c_str(), port, s_fixedWidth, s_smallFont, s_bigFont, SetWindowTitleCallback, SetupScaleCallback, AttentionCallback, s_config, s_achievements ); + } } } if( s_config.memoryLimit )