From ae7eed06cfb8d1f9487b51536f4385bb0e82e9df Mon Sep 17 00:00:00 2001 From: Alex Orlov Date: Mon, 15 Aug 2016 13:58:06 -0700 Subject: [PATCH] Don't derive name on singleton creation Summary: instead fetch it only on exception Reviewed By: andriigrynenko Differential Revision: D3718303 fbshipit-source-id: a021d150f20ab00fe8146f17b19a69fa0da2b0da --- folly/Singleton-inl.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/folly/Singleton-inl.h b/folly/Singleton-inl.h index a326b12b..83dbd2f6 100644 --- a/folly/Singleton-inl.h +++ b/folly/Singleton-inl.h @@ -233,17 +233,16 @@ void SingletonHolder::createInstance() { auto print_destructor_stack_trace = std::make_shared>(false); auto teardown = teardown_; - auto type_name = type().name(); // Can't use make_shared -- no support for a custom deleter, sadly. std::shared_ptr instance( create_(), - [destroy_baton, print_destructor_stack_trace, teardown, type_name] + [destroy_baton, print_destructor_stack_trace, teardown, type = type()] (T* instance_ptr) mutable { teardown(instance_ptr); destroy_baton->post(); if (print_destructor_stack_trace->load()) { - std::string output = "Singleton " + type_name + " was destroyed.\n"; + std::string output = "Singleton " + type.name() + " was destroyed.\n"; auto stack_trace_getter = SingletonVault::stackTraceGetter().load(); auto stack_trace = stack_trace_getter ? stack_trace_getter() : ""; -- 2.34.1