[Lldb-commits] [lldb] e7c48ff - [lldb][NFCI] Avoid construction of temporary std::strings in Variable
Alex Langford via lldb-commits
lldb-commits at lists.llvm.org
Tue Jul 11 10:23:02 PDT 2023
Author: Alex Langford
Date: 2023-07-11T10:22:02-07:00
New Revision: e7c48ffde1c8137822a1b0a1ba6c4be5b4624aa6
URL: https://github.com/llvm/llvm-project/commit/e7c48ffde1c8137822a1b0a1ba6c4be5b4624aa6
DIFF: https://github.com/llvm/llvm-project/commit/e7c48ffde1c8137822a1b0a1ba6c4be5b4624aa6.diff
LOG: [lldb][NFCI] Avoid construction of temporary std::strings in Variable
A common thing to do is to call `str().c_str()` to get a null-terminated
string out of an existing StringRef. Most of the time this is to be able
to use a printf-style format string. However, llvm::formatv can handle
StringRefs without the need for the additional allocation. Using that
makes more sense.
Differential Revision: https://reviews.llvm.org/D154890
Added:
Modified:
lldb/source/Symbol/Variable.cpp
Removed:
################################################################################
diff --git a/lldb/source/Symbol/Variable.cpp b/lldb/source/Symbol/Variable.cpp
index 5e1996b13bcccd..85ceadd20c611e 100644
--- a/lldb/source/Symbol/Variable.cpp
+++ b/lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@ Status Variable::GetValuesForVariableExpressionPath(
llvm::SmallVector<llvm::StringRef, 2> matches;
variable_list.Clear();
if (!g_regex.Execute(variable_expr_path, &matches)) {
- error.SetErrorStringWithFormat(
- "unable to extract a variable name from '%s'",
- variable_expr_path.str().c_str());
+ error.SetErrorStringWithFormatv(
+ "unable to extract a variable name from '{0}'", variable_expr_path);
return error;
}
std::string variable_name = matches[1].str();
@@ -411,10 +410,9 @@ Status Variable::GetValuesForVariableExpressionPath(
valobj_sp = variable_valobj_sp->GetValueForExpressionPath(
variable_sub_expr_path);
if (!valobj_sp) {
- error.SetErrorStringWithFormat(
- "invalid expression path '%s' for variable '%s'",
- variable_sub_expr_path.str().c_str(),
- var_sp->GetName().GetCString());
+ error.SetErrorStringWithFormatv(
+ "invalid expression path '{0}' for variable '{1}'",
+ variable_sub_expr_path, var_sp->GetName().GetCString());
variable_list.RemoveVariableAtIndex(i);
continue;
}
More information about the lldb-commits
mailing list