Skip to content

[lldb] Use llvm::unique (NFC) #139910

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

Conversation

kazutakahirata
Copy link
Contributor

While I am at it, this patch removes the "if" statement.
std::vector::erase(first, last) doesn't do anything when
first == last.

While I am at it, this patch removes the "if" statement.
std::vector::erase(first, last) doesn't do anything when
first == last.
@llvmbot
Copy link
Member

llvmbot commented May 14, 2025

@llvm/pr-subscribers-lldb

Author: Kazu Hirata (kazutakahirata)

Changes

While I am at it, this patch removes the "if" statement.
std::vector::erase(first, last) doesn't do anything when
first == last.


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

1 Files Affected:

  • (modified) lldb/source/Target/DynamicRegisterInfo.cpp (+1-4)
diff --git a/lldb/source/Target/DynamicRegisterInfo.cpp b/lldb/source/Target/DynamicRegisterInfo.cpp
index 9ad98a41c688c..b964dc5877a97 100644
--- a/lldb/source/Target/DynamicRegisterInfo.cpp
+++ b/lldb/source/Target/DynamicRegisterInfo.cpp
@@ -497,10 +497,7 @@ void DynamicRegisterInfo::Finalize(const ArchSpec &arch) {
        pos != end; ++pos) {
     if (pos->second.size() > 1) {
       llvm::sort(pos->second);
-      reg_num_collection::iterator unique_end =
-          std::unique(pos->second.begin(), pos->second.end());
-      if (unique_end != pos->second.end())
-        pos->second.erase(unique_end, pos->second.end());
+      pos->second.erase(llvm::unique(pos->second), pos->second.end());
     }
     assert(!pos->second.empty());
     if (pos->second.back() != LLDB_INVALID_REGNUM)

Copy link
Member

@bulbazord bulbazord left a comment

Choose a reason for hiding this comment

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

Makes sense. std::unique doesn't invalidate the end iterator, so I believe this should be ok.

@kazutakahirata kazutakahirata merged commit 1f570b1 into llvm:main May 15, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_001_range_llvm_unique_lldb branch May 15, 2025 14:16
TIFitis pushed a commit to TIFitis/llvm-project that referenced this pull request May 19, 2025
While I am at it, this patch removes the "if" statement.
std::vector::erase(first, last) doesn't do anything when
first == last.
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.

3 participants