[DebugInfo] Use shrink_to_fit to simplify code. NFCI.

llvm-svn: 309683
This commit is contained in:
Benjamin Kramer 2017-08-01 14:38:08 +00:00
parent 442e722c1e
commit 295cf4de37
2 changed files with 4 additions and 14 deletions

View File

@ -107,8 +107,8 @@ void DWARFDebugAranges::construct() {
assert(ValidCUs.empty()); assert(ValidCUs.empty());
// Endpoints are not needed now. // Endpoints are not needed now.
std::vector<RangeEndpoint> EmptyEndpoints; Endpoints.clear();
EmptyEndpoints.swap(Endpoints); Endpoints.shrink_to_fit();
} }
uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const { uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const {

View File

@ -307,18 +307,8 @@ bool DWARFUnit::parseDWO() {
void DWARFUnit::clearDIEs(bool KeepCUDie) { void DWARFUnit::clearDIEs(bool KeepCUDie) {
if (DieArray.size() > (unsigned)KeepCUDie) { if (DieArray.size() > (unsigned)KeepCUDie) {
// std::vectors never get any smaller when resized to a smaller size, DieArray.resize((unsigned)KeepCUDie);
// or when clear() or erase() are called, the size will report that it DieArray.shrink_to_fit();
// is smaller, but the memory allocated remains intact (call capacity()
// to see this). So we need to create a temporary vector and swap the
// contents which will cause just the internal pointers to be swapped
// so that when temporary vector goes out of scope, it will destroy the
// contents.
std::vector<DWARFDebugInfoEntry> TmpArray;
DieArray.swap(TmpArray);
// Save at least the compile unit DIE
if (KeepCUDie)
DieArray.push_back(TmpArray.front());
} }
} }