summaryrefslogtreecommitdiff
path: root/lldb/source/Commands/CommandObjectDWIMPrint.cpp
diff options
context:
space:
mode:
authorDave Lee <davelee.com@gmail.com>2025-03-07 21:57:05 -0800
committerGitHub <noreply@github.com>2025-03-07 21:57:05 -0800
commit61efe360f9ba70736ca27ad289277c5c8268ffc0 (patch)
tree51e20e20aa61d1e0cf7dd83965a9f17bac3e150f /lldb/source/Commands/CommandObjectDWIMPrint.cpp
parentf5789824900d61a8fbabe17c4449ff2e31d24ad4 (diff)
[lldb] Avoid unnecessary regex check in dwim-print (#114608)
An (unmeasured) improvement to performance of `dwim-print` when used as `po`. This change lifts the check for `note_shown` to the top of the lambda, to avoid all subsequent work when the hint has already been shown. The main effect is to avoid performing a regex match when the hint is not going to be shown. This change also constructs the `std::regex` only once, by making it static.
Diffstat (limited to 'lldb/source/Commands/CommandObjectDWIMPrint.cpp')
-rw-r--r--lldb/source/Commands/CommandObjectDWIMPrint.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/lldb/source/Commands/CommandObjectDWIMPrint.cpp b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
index 04142427717b..17c60297a521 100644
--- a/lldb/source/Commands/CommandObjectDWIMPrint.cpp
+++ b/lldb/source/Commands/CommandObjectDWIMPrint.cpp
@@ -101,6 +101,10 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
// Add a hint if object description was requested, but no description
// function was implemented.
auto maybe_add_hint = [&](llvm::StringRef output) {
+ static bool note_shown = false;
+ if (note_shown)
+ return;
+
// Identify the default output of object description for Swift and
// Objective-C
// "<Name: 0x...>. The regex is:
@@ -110,17 +114,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
// - Followed by 5 or more hex digits.
// - Followed by ">".
// - End with zero or more whitespace characters.
- const std::regex swift_class_regex("^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
+ static const std::regex swift_class_regex(
+ "^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
if (GetDebugger().GetShowDontUsePoHint() && target_ptr &&
(language == lldb::eLanguageTypeSwift ||
language == lldb::eLanguageTypeObjC) &&
std::regex_match(output.data(), swift_class_regex)) {
- static bool note_shown = false;
- if (note_shown)
- return;
-
result.AppendNote(
"object description requested, but type doesn't implement "
"a custom object description. Consider using \"p\" instead of "