Skip to content

[lldb] Refactor string manipulation in Debugger.cpp #92565

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 5, 2024

Conversation

aabhinavg
Copy link
Member

Summary of Changes:

Replaced the ineffective call to substr with a more efficient use of resize to truncate the string.
Adjusted the code to use 'resize' instead of 'substr' for better performance and readability.
Removed unwanted file from the previous commit.
Fixes: #91209

@aabhinavg aabhinavg requested a review from JDevlieghere as a code owner May 17, 2024 15:55
@llvmbot llvmbot added the lldb label May 17, 2024
@llvmbot
Copy link
Member

llvmbot commented May 17, 2024

@llvm/pr-subscribers-lldb

Author: None (aabhinavg)

Changes

Summary of Changes:

Replaced the ineffective call to substr with a more efficient use of resize to truncate the string.
Adjusted the code to use 'resize' instead of 'substr' for better performance and readability.
Removed unwanted file from the previous commit.
Fixes: #91209


Full diff: https://github.com/llvm/llvm-project/pull/92565.diff

1 Files Affected:

  • (modified) lldb/source/Core/Debugger.cpp (+1-1)
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 9951fbcd3e7c3..70303173925e3 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -2067,7 +2067,7 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
   const uint32_t term_width = GetTerminalWidth();
   const uint32_t ellipsis = 3;
   if (message.size() + ellipsis >= term_width)
-    message = message.substr(0, term_width - ellipsis);
+    message.resize(message.size() - ellipsis);
 
   const bool use_color = GetUseColor();
   llvm::StringRef ansi_prefix = GetShowProgressAnsiPrefix();

Copy link

⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo.
Please turn off Keep my email addresses private setting in your account.
See LLVM Discourse for more information.

@@ -2067,7 +2067,7 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
const uint32_t term_width = GetTerminalWidth();
const uint32_t ellipsis = 3;
if (message.size() + ellipsis >= term_width)
message = message.substr(0, term_width - ellipsis);
message.resize(message.size() - ellipsis);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why term_width does not appear in the new patch?

@JDevlieghere
Copy link
Member

@aabhinavg Please let me know when you've changed the GitHub private e-mail address setting and I'd be happy to merge this for you.

@DavidSpickett DavidSpickett changed the title [lldb] Refactor string manipulation in Debugger.cpp (#91209) [lldb] Refactor string manipulation in Debugger.cpp Nov 5, 2024
@DavidSpickett DavidSpickett merged commit bf01bb8 into llvm:main Nov 5, 2024
5 checks passed
PhilippRados pushed a commit to PhilippRados/llvm-project that referenced this pull request Nov 6, 2024
Summary of Changes:

Replaced the ineffective call to `substr` with a more efficient use of
`resize` to truncate the string.
Adjusted the code to use 'resize' instead of 'substr' for better
performance and readability.
Removed unwanted file from the previous commit.
Fixes: llvm#91209

---------

Co-authored-by: aabhinavg <[email protected]>
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Dec 4, 2024
…7b956371e

Local branch amd-gfx b797b95 Manual merge remote-tracking branch llvm-org/main into amd-gfx
Remote branch main bf01bb8 [lldb] Refactor string manipulation in Debugger.cpp (llvm#92565)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

lldb/source/Core/Debugger.cpp:2069: Clumsy string resize ?
7 participants