]> git.hungrycats.org Git - bees/commitdiff
trace: avoid one copy in every trace function
authorZygo Blaxell <bees@furryterror.org>
Thu, 13 Feb 2025 01:10:12 +0000 (20:10 -0500)
committerZygo Blaxell <bees@furryterror.org>
Fri, 14 Feb 2025 04:59:42 +0000 (23:59 -0500)
While investigating https://github.com/Zygo/bees/issues/282 I noticed that
we're doing at least one unnecessary extra copy of the functor in BEESTRACE.
Get rid of it with a const reference.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
src/bees-trace.cc
src/bees.h

index 5e585323e2a25e2b4560c0c93caa8e58f6947da9..81b70d577c3a337d98c6744604ffbd30cf40e5b7 100644 (file)
@@ -49,7 +49,7 @@ BeesTracer::~BeesTracer()
        }
 }
 
-BeesTracer::BeesTracer(function<void()> f, bool silent) :
+BeesTracer::BeesTracer(const function<void()> &f, bool silent) :
        m_func(f)
 {
        m_next_tracer = tl_next_tracer;
index 10ed7f638f7fff0224677cd8981c1efab2e31aab..888f91edcfcdb906745612e32c878bc37f362c6d 100644 (file)
@@ -193,7 +193,7 @@ class BeesTracer {
        thread_local static bool tl_silent;
        thread_local static bool tl_first;
 public:
-       BeesTracer(function<void()> f, bool silent = false);
+       BeesTracer(const function<void()> &f, bool silent = false);
        ~BeesTracer();
        static void trace_now();
        static bool get_silent();