From a0221c86602848ab08068ab7dcf4951ed334e847 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 16 Apr 2023 16:44:18 +0200 Subject: [PATCH] Pass function objects through const references. --- profiler/src/Backend.hpp | 2 +- profiler/src/BackendGlfw.cpp | 2 +- profiler/src/BackendWayland.cpp | 2 +- profiler/src/HttpRequest.cpp | 2 +- profiler/src/HttpRequest.hpp | 2 +- profiler/src/RunQueue.cpp | 2 +- profiler/src/RunQueue.hpp | 2 +- profiler/src/main.cpp | 2 +- server/TracyFileselector.cpp | 8 ++++---- server/TracyFileselector.hpp | 4 ++-- server/TracyStringDiscovery.hpp | 2 +- server/TracyTexture.cpp | 2 +- server/TracyTexture.hpp | 2 +- server/TracyView.cpp | 4 ++-- server/TracyView.hpp | 8 ++++---- server/TracyView_Memory.cpp | 2 +- 16 files changed, 24 insertions(+), 24 deletions(-) diff --git a/profiler/src/Backend.hpp b/profiler/src/Backend.hpp index 34b6dad5..2f4262a3 100644 --- a/profiler/src/Backend.hpp +++ b/profiler/src/Backend.hpp @@ -11,7 +11,7 @@ class RunQueue; class Backend { public: - Backend( const char* title, std::function redraw, RunQueue* mainThreadTasks ); + Backend( const char* title, const std::function& redraw, RunQueue* mainThreadTasks ); ~Backend(); void Show(); diff --git a/profiler/src/BackendGlfw.cpp b/profiler/src/BackendGlfw.cpp index 94a672b9..f3525ee9 100644 --- a/profiler/src/BackendGlfw.cpp +++ b/profiler/src/BackendGlfw.cpp @@ -60,7 +60,7 @@ static void glfw_window_iconify_callback( GLFWwindow*, int iconified ) } -Backend::Backend( const char* title, std::function redraw, RunQueue* mainThreadTasks ) +Backend::Backend( const char* title, const std::function& redraw, RunQueue* mainThreadTasks ) { glfwSetErrorCallback( glfw_error_callback ); if( !glfwInit() ) exit( 1 ); diff --git a/profiler/src/BackendWayland.cpp b/profiler/src/BackendWayland.cpp index 30ea8dc1..19f5ce5c 100644 --- a/profiler/src/BackendWayland.cpp +++ b/profiler/src/BackendWayland.cpp @@ -630,7 +630,7 @@ static void SetupCursor() s_cursorY = cursor->images[0]->hotspot_y / s_maxScale; } -Backend::Backend( const char* title, std::function redraw, RunQueue* mainThreadTasks ) +Backend::Backend( const char* title, const std::function& redraw, RunQueue* mainThreadTasks ) { s_redraw = redraw; s_mainThreadTasks = mainThreadTasks; diff --git a/profiler/src/HttpRequest.cpp b/profiler/src/HttpRequest.cpp index c14c3789..64445d94 100644 --- a/profiler/src/HttpRequest.cpp +++ b/profiler/src/HttpRequest.cpp @@ -72,7 +72,7 @@ static const char* GetOsInfo() return buf; } -void HttpRequest( const char* server, const char* resource, int port, std::function cb ) +void HttpRequest( const char* server, const char* resource, int port, const std::function& cb ) { tracy::Socket sock; if( !sock.ConnectBlocking( server, port ) ) return; diff --git a/profiler/src/HttpRequest.hpp b/profiler/src/HttpRequest.hpp index 7aa86c5c..cdbc13d9 100644 --- a/profiler/src/HttpRequest.hpp +++ b/profiler/src/HttpRequest.hpp @@ -3,6 +3,6 @@ #include -void HttpRequest( const char* server, const char* resource, int port, std::function cb ); +void HttpRequest( const char* server, const char* resource, int port, const std::function& cb ); #endif diff --git a/profiler/src/RunQueue.cpp b/profiler/src/RunQueue.cpp index 42d07c17..24883b13 100644 --- a/profiler/src/RunQueue.cpp +++ b/profiler/src/RunQueue.cpp @@ -5,7 +5,7 @@ RunQueue::RunQueue() { } -void RunQueue::Queue( std::function cb, bool forceDelay ) +void RunQueue::Queue( const std::function& cb, bool forceDelay ) { if( !forceDelay && std::this_thread::get_id() == m_mainThread ) { diff --git a/profiler/src/RunQueue.hpp b/profiler/src/RunQueue.hpp index a904ba62..e771b9b3 100644 --- a/profiler/src/RunQueue.hpp +++ b/profiler/src/RunQueue.hpp @@ -11,7 +11,7 @@ class RunQueue public: RunQueue(); - void Queue( std::function cb, bool forceDelay = false ); + void Queue( const std::function& cb, bool forceDelay = false ); void Run(); private: diff --git a/profiler/src/main.cpp b/profiler/src/main.cpp index 4dc01b2a..399c9154 100644 --- a/profiler/src/main.cpp +++ b/profiler/src/main.cpp @@ -114,7 +114,7 @@ static void AttentionCallback() static void DrawContents(); -void RunOnMainThread( std::function cb, bool forceDelay = false ) +static void RunOnMainThread( const std::function& cb, bool forceDelay = false ) { mainThreadTasks.Queue( cb, forceDelay ); } diff --git a/server/TracyFileselector.cpp b/server/TracyFileselector.cpp index 4976ac64..bcfc162c 100644 --- a/server/TracyFileselector.cpp +++ b/server/TracyFileselector.cpp @@ -50,7 +50,7 @@ extern "C" int nativeOpenFile() } #endif -static bool OpenFileImpl( const char* ext, const char* desc, std::function callback ) +static bool OpenFileImpl( const char* ext, const char* desc, const std::function& callback ) { #ifndef TRACY_NO_FILESELECTOR # ifdef __EMSCRIPTEN__ @@ -93,7 +93,7 @@ static bool OpenFileImpl( const char* ext, const char* desc, std::function callback ) +static bool SaveFileImpl( const char* ext, const char* desc, const std::function& callback ) { #if !defined TRACY_NO_FILESELECTOR && !defined __EMSCRIPTEN__ nfdu8filteritem_t filter = { desc, ext }; @@ -113,12 +113,12 @@ static bool SaveFileImpl( const char* ext, const char* desc, std::function callback ) +void OpenFile( const char* ext, const char* desc, const std::function& callback ) { if( !OpenFileImpl( ext, desc, callback ) ) s_hasFailed = true; } -void SaveFile( const char* ext, const char* desc, std::function callback ) +void SaveFile( const char* ext, const char* desc, const std::function& callback ) { if( !SaveFileImpl( ext, desc, callback ) ) s_hasFailed = true; } diff --git a/server/TracyFileselector.hpp b/server/TracyFileselector.hpp index cd22d7a8..7fd8ba44 100644 --- a/server/TracyFileselector.hpp +++ b/server/TracyFileselector.hpp @@ -10,8 +10,8 @@ void Init(); void Shutdown(); bool HasFailed(); -void OpenFile( const char* ext, const char* desc, std::function callback ); -void SaveFile( const char* ext, const char* desc, std::function callback ); +void OpenFile( const char* ext, const char* desc, const std::function& callback ); +void SaveFile( const char* ext, const char* desc, const std::function& callback ); } diff --git a/server/TracyStringDiscovery.hpp b/server/TracyStringDiscovery.hpp index 4cb70f5e..066c4422 100644 --- a/server/TracyStringDiscovery.hpp +++ b/server/TracyStringDiscovery.hpp @@ -44,7 +44,7 @@ public: m_pending.erase( pit ); } - tracy_force_inline T Retrieve( uint64_t name, std::function Create, std::function Query ) + tracy_force_inline T Retrieve( uint64_t name, const std::function& Create, const std::function& Query ) { auto it = m_map.find( name ); if( it == m_map.end() ) diff --git a/server/TracyTexture.cpp b/server/TracyTexture.cpp index be400278..66defd93 100644 --- a/server/TracyTexture.cpp +++ b/server/TracyTexture.cpp @@ -51,7 +51,7 @@ void* MakeTexture() return (void*)(intptr_t)tex; } -void FreeTexture( void* _tex, void(*runOnMainThread)(std::function, bool) ) +void FreeTexture( void* _tex, void(*runOnMainThread)(const std::function&, bool) ) { auto tex = (GLuint)(intptr_t)_tex; runOnMainThread( [tex] { glDeleteTextures( 1, &tex ); }, false ); diff --git a/server/TracyTexture.hpp b/server/TracyTexture.hpp index bcc8a455..cc2f9160 100644 --- a/server/TracyTexture.hpp +++ b/server/TracyTexture.hpp @@ -8,7 +8,7 @@ namespace tracy void InitTexture(); void* MakeTexture(); -void FreeTexture( void* tex, void(*runOnMainThread)(std::function, bool) ); +void FreeTexture( void* tex, void(*runOnMainThread)(const std::function&, bool) ); void UpdateTexture( void* tex, const char* data, int w, int h ); void UpdateTextureRGBA( void* tex, void* data, int w, int h ); diff --git a/server/TracyView.cpp b/server/TracyView.cpp index dd04fa52..7deb272d 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -44,7 +44,7 @@ namespace tracy double s_time = 0; -View::View( void(*cbMainThread)(std::function, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ) +View::View( void(*cbMainThread)(const std::function&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ) : m_worker( addr, port ) , m_staticView( false ) , m_viewMode( ViewMode::LastFrames ) @@ -68,7 +68,7 @@ View::View( void(*cbMainThread)(std::function, bool), const char* addr, InitTextEditor( fixedWidth ); } -View::View( void(*cbMainThread)(std::function, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ) +View::View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ) : m_worker( f ) , m_filename( f.GetFilename() ) , m_staticView( true ) diff --git a/server/TracyView.hpp b/server/TracyView.hpp index a04b68bf..1eeb22be 100644 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -99,8 +99,8 @@ public: using SetScaleCallback = void(*)( float, ImFont*&, ImFont*&, ImFont*& ); using AttentionCallback = void(*)(); - View( void(*cbMainThread)(std::function, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ); - View( void(*cbMainThread)(std::function, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ); + View( void(*cbMainThread)(const std::function&, bool), const char* addr, uint16_t port, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ); + View( void(*cbMainThread)(const std::function&, bool), FileRead& f, ImFont* fixedWidth, ImFont* smallFont, ImFont* bigFont, SetTitleCallback stcb, SetScaleCallback sscb, AttentionCallback acb ); ~View(); bool Draw(); @@ -259,7 +259,7 @@ private: void DrawSourceTooltip( const char* filename, uint32_t line, int before = 3, int after = 3, bool separateTooltip = true ); void DrawWaitStacks(); - void ListMemData( std::vector& vec, std::function DrawAddress, const char* id = nullptr, int64_t startTime = -1, uint64_t pool = 0 ); + void ListMemData( std::vector& vec, const std::function& DrawAddress, const char* id = nullptr, int64_t startTime = -1, uint64_t pool = 0 ); unordered_flat_map GetCallstackPaths( const MemData& mem, MemRange memRange ) const; unordered_flat_map GetCallstackFrameTreeBottomUp( const MemData& mem ) const; @@ -578,7 +578,7 @@ private: unordered_flat_map m_visMap; - void(*m_cbMainThread)(std::function, bool); + void(*m_cbMainThread)(const std::function&, bool); int m_gpuIdx = 0; diff --git a/server/TracyView_Memory.cpp b/server/TracyView_Memory.cpp index 93d0b3b7..f5a4bbaa 100644 --- a/server/TracyView_Memory.cpp +++ b/server/TracyView_Memory.cpp @@ -650,7 +650,7 @@ void View::DrawMemoryAllocWindow() if( !show ) m_memoryAllocInfoWindow = -1; } -void View::ListMemData( std::vector& vec, std::function DrawAddress, const char* id, int64_t startTime, uint64_t pool ) +void View::ListMemData( std::vector& vec, const std::function& DrawAddress, const char* id, int64_t startTime, uint64_t pool ) { if( startTime == -1 ) startTime = 0; if( ImGui::BeginTable( "##mem", 8, ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable | ImGuiTableFlags_Hideable | ImGuiTableFlags_Sortable | ImGuiTableFlags_BordersInnerV | ImGuiTableFlags_ScrollY, ImVec2( 0, ImGui::GetTextLineHeightWithSpacing() * std::min( 1+vec.size(), 15 ) ) ) )