[Lldb-commits] [PATCH] D154890: [lldb][NFCI] Avoid construction of temporary std::strings in Variable

2023-07-11 Thread Alex Langford via Phabricator via lldb-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe7c48ffde1c8: [lldb][NFCI] Avoid construction of temporary 
std::strings in Variable (authored by bulbazord).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154890/new/

https://reviews.llvm.org/D154890

Files:
  lldb/source/Symbol/Variable.cpp


Index: lldb/source/Symbol/Variable.cpp
===
--- lldb/source/Symbol/Variable.cpp
+++ lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, )) {
-  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 @@
 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;
 }


Index: lldb/source/Symbol/Variable.cpp
===
--- lldb/source/Symbol/Variable.cpp
+++ lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, )) {
-  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 @@
 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;
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154890: [lldb][NFCI] Avoid construction of temporary std::strings in Variable

2023-07-10 Thread Jonas Devlieghere via Phabricator via lldb-commits
JDevlieghere accepted this revision.
JDevlieghere added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154890/new/

https://reviews.llvm.org/D154890

___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [PATCH] D154890: [lldb][NFCI] Avoid construction of temporary std::strings in Variable

2023-07-10 Thread Alex Langford via Phabricator via lldb-commits
bulbazord created this revision.
bulbazord added reviewers: JDevlieghere, mib, jingham, fdeazeve.
Herald added a project: All.
bulbazord requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D154890

Files:
  lldb/source/Symbol/Variable.cpp


Index: lldb/source/Symbol/Variable.cpp
===
--- lldb/source/Symbol/Variable.cpp
+++ lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, )) {
-  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 @@
 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;
 }


Index: lldb/source/Symbol/Variable.cpp
===
--- lldb/source/Symbol/Variable.cpp
+++ lldb/source/Symbol/Variable.cpp
@@ -380,9 +380,8 @@
 llvm::SmallVector matches;
 variable_list.Clear();
 if (!g_regex.Execute(variable_expr_path, )) {
-  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 @@
 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;
 }
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits