[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
This commit is contained in:
Alex Langford
2023-05-18 15:31:25 -07:00
parent 12f3ae6fe6
commit e8d3f061ba

View File

@@ -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 += '+';