Skip to content

Commit 3f25aa8

Browse files
committed
[lldb] Avoid unnecessary regex check in dwim-print (llvm#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. (cherry picked from commit 61efe36)
1 parent 00626f5 commit 3f25aa8

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
103103
// Add a hint if object description was requested, but no description
104104
// function was implemented.
105105
auto maybe_add_hint = [&](llvm::StringRef output) {
106+
static bool note_shown = false;
107+
if (note_shown)
108+
return;
109+
106110
// Identify the default output of object description for Swift and
107111
// Objective-C
108112
// "<Name: 0x...>. The regex is:
@@ -112,17 +116,14 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
112116
// - Followed by 5 or more hex digits.
113117
// - Followed by ">".
114118
// - End with zero or more whitespace characters.
115-
const std::regex swift_class_regex("^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
119+
static const std::regex swift_class_regex(
120+
"^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
116121

117122
if (GetDebugger().GetShowDontUsePoHint() && target_ptr &&
118123
(language == lldb::eLanguageTypeSwift ||
119124
language == lldb::eLanguageTypeObjC) &&
120125
std::regex_match(output.data(), swift_class_regex)) {
121126

122-
static bool note_shown = false;
123-
if (note_shown)
124-
return;
125-
126127
result.AppendNote(
127128
"object description requested, but type doesn't implement "
128129
"a custom object description. Consider using \"p\" instead of "

0 commit comments

Comments
 (0)