[Lldb-commits] [lldb] e8d3f06 - [lldb][NFCI] Pre-allocate storage in ObjCLanguage::MethodName::GetFullNameWithoutCategory

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Thu May 18 16:23:26 PDT 2023


Author: Alex Langford
Date: 2023-05-18T16:23:15-07:00
New Revision: e8d3f061ba415e9f95739e0004fb75552d68df86

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

LOG: [lldb][NFCI] Pre-allocate storage in ObjCLanguage::MethodName::GetFullNameWithoutCategory

The size of a full ObjC MethodName can vary somewhat, but it is
computable ahead of time.

Using a reasonably sized ObjC application, this actually improves the
time it takes to initialize symbol indexes for ObjC names ever so
slightly. Additionally, I found that the variability in time also was
improved considerably.

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

Added: 
    

Modified: 
    lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
index fb87d5d80b96c..3a9e287158329 100644
--- a/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
+++ b/lldb/source/Plugins/Language/ObjC/ObjCLanguage.cpp
@@ -152,7 +152,15 @@ std::string ObjCLanguage::MethodName::GetFullNameWithoutCategory() const {
 
   llvm::StringRef class_name = GetClassName();
   llvm::StringRef selector_name = GetSelector();
+
+  // Compute the total size to avoid reallocations
+  // class name + selector name + '[' + ' ' + ']'
+  size_t total_size = class_name.size() + selector_name.size() + 3;
+  if (m_type != eTypeUnspecified)
+    total_size++; // For + or -
+
   std::string name_sans_category;
+  name_sans_category.reserve(total_size);
 
   if (m_type == eTypeClassMethod)
     name_sans_category += '+';


        


More information about the lldb-commits mailing list