From 295cf4de37a4be7de2c9fa424da381cbb15df478 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Tue, 1 Aug 2017 14:38:08 +0000 Subject: [PATCH] [DebugInfo] Use shrink_to_fit to simplify code. NFCI. llvm-svn: 309683 --- llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp | 4 ++-- llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp | 14 ++------------ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp index 65c486a6cf39..a3ecb15e3661 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFDebugAranges.cpp @@ -107,8 +107,8 @@ void DWARFDebugAranges::construct() { assert(ValidCUs.empty()); // Endpoints are not needed now. - std::vector EmptyEndpoints; - EmptyEndpoints.swap(Endpoints); + Endpoints.clear(); + Endpoints.shrink_to_fit(); } uint32_t DWARFDebugAranges::findAddress(uint64_t Address) const { diff --git a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp index f55ece2fdfdf..0a12fb2ecaa6 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp @@ -307,18 +307,8 @@ bool DWARFUnit::parseDWO() { void DWARFUnit::clearDIEs(bool KeepCUDie) { if (DieArray.size() > (unsigned)KeepCUDie) { - // std::vectors never get any smaller when resized to a smaller size, - // or when clear() or erase() are called, the size will report that it - // 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 TmpArray; - DieArray.swap(TmpArray); - // Save at least the compile unit DIE - if (KeepCUDie) - DieArray.push_back(TmpArray.front()); + DieArray.resize((unsigned)KeepCUDie); + DieArray.shrink_to_fit(); } }