[llvm] 9be4387 - Support: Avoid unnecessary std::function for SignpostEmitterImpl::SignpostLog

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 8 16:35:01 PDT 2021


Author: Duncan P. N. Exon Smith
Date: 2021-04-08T16:34:22-07:00
New Revision: 9be43874343b0aa2221497830d0356eb4b7eecfa

URL: https://github.com/llvm/llvm-project/commit/9be43874343b0aa2221497830d0356eb4b7eecfa
DIFF: https://github.com/llvm/llvm-project/commit/9be43874343b0aa2221497830d0356eb4b7eecfa.diff

LOG: Support: Avoid unnecessary std::function for SignpostEmitterImpl::SignpostLog

The destructor for SignPostEmitterImpl::SignpostLog is known statically. Avoid
the unnecessary vtable indirection through std::function in the std::unique_ptr
by turning LogDeleter into a struct. No real functionality change here.

Differential Revision: https://reviews.llvm.org/D100154

Added: 
    

Modified: 
    llvm/lib/Support/Signposts.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/Signposts.cpp b/llvm/lib/Support/Signposts.cpp
index 80ef7d19e11d..586f1db50759 100644
--- a/llvm/lib/Support/Signposts.cpp
+++ b/llvm/lib/Support/Signposts.cpp
@@ -29,15 +29,17 @@ os_log_t *LogCreator() {
   *X = os_log_create("org.llvm.signposts", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
   return X;
 }
-void LogDeleter(os_log_t *X) {
-  os_release(*X);
-  delete X;
-}
+struct LogDeleter {
+  void operator()(os_log_t *X) const {
+    os_release(*X);
+    delete X;
+  }
+};
 } // end anonymous namespace
 
 namespace llvm {
 class SignpostEmitterImpl {
-  using LogPtrTy = std::unique_ptr<os_log_t, std::function<void(os_log_t *)>>;
+  using LogPtrTy = std::unique_ptr<os_log_t, LogDeleter>;
   using LogTy = LogPtrTy::element_type;
 
   LogPtrTy SignpostLog;
@@ -59,7 +61,7 @@ class SignpostEmitterImpl {
   }
 
 public:
-  SignpostEmitterImpl() : SignpostLog(LogCreator(), LogDeleter) {}
+  SignpostEmitterImpl() : SignpostLog(LogCreator()) {}
 
   bool isEnabled() const {
     if (SIGNPOSTS_AVAILABLE())


        


More information about the llvm-commits mailing list