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 += '+'; _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits