Skip to content

Commit e244e45

Browse files
committed
[lldb] Avoid unnecessary regex check in dwim-print
1 parent c1df376 commit e244e45

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

lldb/source/Commands/CommandObjectDWIMPrint.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
101101
// Add a hint if object description was requested, but no description
102102
// function was implemented.
103103
auto maybe_add_hint = [&](llvm::StringRef output) {
104+
static bool note_shown = false;
105+
if (note_shown)
106+
return;
107+
104108
// Identify the default output of object description for Swift and
105109
// Objective-C
106110
// "<Name: 0x...>. The regex is:
@@ -110,20 +114,16 @@ void CommandObjectDWIMPrint::DoExecute(StringRef command,
110114
// - Followed by 5 or more hex digits.
111115
// - Followed by ">".
112116
// - End with zero or more whitespace characters.
113-
const std::regex swift_class_regex("^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
117+
static const std::regex class_po_regex("^<\\S+: 0x[[:xdigit:]]{5,}>\\s*$");
114118

115119
if (GetDebugger().GetShowDontUsePoHint() && target_ptr &&
116120
(language == lldb::eLanguageTypeSwift ||
117121
language == lldb::eLanguageTypeObjC) &&
118-
std::regex_match(output.data(), swift_class_regex)) {
119-
120-
static bool note_shown = false;
121-
if (note_shown)
122-
return;
122+
std::regex_match(output.data(), class_po_regex)) {
123123

124124
result.GetOutputStream()
125-
<< "note: object description requested, but type doesn't implement "
126-
"a custom object description. Consider using \"p\" instead of "
125+
<< "note: object description requested, but type doesn't implement a "
126+
"custom object description. Consider using \"p\" instead of "
127127
"\"po\" (this note will only be shown once per debug session).\n";
128128
note_shown = true;
129129
}

0 commit comments

Comments
 (0)