Skip to content

[lldb][Symtab][NFCI] Replace vector::swap with shrink_to_fit #70918

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 1 commit into from
Nov 1, 2023

Conversation

Michael137
Copy link
Member

@Michael137 Michael137 commented Nov 1, 2023

Replaces the old idiom (of swapping the container to shrink it) with the newer STL alternative.

Similar transition in LLDB was done in: https://reviews.llvm.org/D47492

@llvmbot
Copy link
Member

llvmbot commented Nov 1, 2023

@llvm/pr-subscribers-lldb

Author: Michael Buch (Michael137)

Changes

Replaces the old idiom of swapping the container to shrink it, with the newer STL alternative.

Similar transition in LLDB was done in: https://reviews.llvm.org/D47492


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

1 Files Affected:

  • (modified) lldb/source/Symbol/Symtab.cpp (+1-4)
diff --git a/lldb/source/Symbol/Symtab.cpp b/lldb/source/Symbol/Symtab.cpp
index 104faac38ffa0fe..1aebe198f9e78ae 100644
--- a/lldb/source/Symbol/Symtab.cpp
+++ b/lldb/source/Symbol/Symtab.cpp
@@ -1010,10 +1010,7 @@ void Symtab::Finalize() {
   // Calculate the size of symbols inside InitAddressIndexes.
   InitAddressIndexes();
   // Shrink to fit the symbols so we don't waste memory
-  if (m_symbols.capacity() > m_symbols.size()) {
-    collection new_symbols(m_symbols.begin(), m_symbols.end());
-    m_symbols.swap(new_symbols);
-  }
+  m_symbols.shrink_to_fit();
   SaveToCache();
 }
 

Copy link
Collaborator

@DavidSpickett DavidSpickett left a comment

Choose a reason for hiding this comment

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

LGTM

@Michael137 Michael137 merged commit bc41b0a into llvm:main Nov 1, 2023
@Michael137 Michael137 deleted the nfc/lldb-symtab-shrink_to_fit branch November 1, 2023 10:44
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