From: Alexey Samsonov Date: Thu, 13 Mar 2014 08:19:59 +0000 (+0000) Subject: [C++11] DWARF parser: use SmallVector for parsed units in DWARFConte... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a2b15f5079534ed51b1f0bf9158a1b3a5f4ae688;p=oota-llvm.git [C++11] DWARF parser: use SmallVector for parsed units in DWARFContext, and delete custom destructors git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203770 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/DebugInfo/DWARFContext.cpp b/lib/DebugInfo/DWARFContext.cpp index 119e3602d0e..94935e25683 100644 --- a/lib/DebugInfo/DWARFContext.cpp +++ b/lib/DebugInfo/DWARFContext.cpp @@ -8,7 +8,6 @@ //===----------------------------------------------------------------------===// #include "DWARFContext.h" -#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringSwitch.h" #include "llvm/Support/Compression.h" @@ -23,13 +22,6 @@ using namespace object; typedef DWARFDebugLine::LineTable DWARFLineTable; -DWARFContext::~DWARFContext() { - DeleteContainerPointers(CUs); - DeleteContainerPointers(TUs); - DeleteContainerPointers(DWOCUs); - DeleteContainerPointers(DWOTUs); -} - static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef Data, bool LittleEndian, bool GnuStyle) { OS << "\n." << Name << " contents:\n"; @@ -125,7 +117,7 @@ void DWARFContext::dump(raw_ostream &OS, DIDumpType DumpType) { savedAddressByteSize = CU->getAddressByteSize(); unsigned stmtOffset = CU->getCompileUnitDIE()->getAttributeValueAsSectionOffset( - CU, DW_AT_stmt_list, -1U); + CU.get(), DW_AT_stmt_list, -1U); if (stmtOffset != -1U) { DataExtractor lineData(getLineSection().Data, isLittleEndian(), savedAddressByteSize); @@ -309,7 +301,7 @@ void DWARFContext::parseCompileUnits() { if (!CU->extract(DIData, &offset)) { break; } - CUs.push_back(CU.release()); + CUs.push_back(std::move(CU)); offset = CUs.back()->getNextUnitOffset(); } } @@ -328,7 +320,7 @@ void DWARFContext::parseTypeUnits() { &I.second.Relocs, isLittleEndian())); if (!TU->extract(DIData, &offset)) break; - TUs.push_back(TU.release()); + TUs.push_back(std::move(TU)); offset = TUs.back()->getNextUnitOffset(); } } @@ -349,7 +341,7 @@ void DWARFContext::parseDWOCompileUnits() { if (!DWOCU->extract(DIData, &offset)) { break; } - DWOCUs.push_back(DWOCU.release()); + DWOCUs.push_back(std::move(DWOCU)); offset = DWOCUs.back()->getNextUnitOffset(); } } @@ -369,7 +361,7 @@ void DWARFContext::parseDWOTypeUnits() { isLittleEndian())); if (!TU->extract(DIData, &offset)) break; - DWOTUs.push_back(TU.release()); + DWOTUs.push_back(std::move(TU)); offset = DWOTUs.back()->getNextUnitOffset(); } } @@ -377,14 +369,17 @@ void DWARFContext::parseDWOTypeUnits() { namespace { struct OffsetComparator { - bool operator()(const DWARFCompileUnit *LHS, - const DWARFCompileUnit *RHS) const { + + bool operator()(const std::unique_ptr &LHS, + const std::unique_ptr &RHS) const { return LHS->getOffset() < RHS->getOffset(); } - bool operator()(const DWARFCompileUnit *LHS, uint32_t RHS) const { + bool operator()(const std::unique_ptr &LHS, + uint32_t RHS) const { return LHS->getOffset() < RHS; } - bool operator()(uint32_t LHS, const DWARFCompileUnit *RHS) const { + bool operator()(uint32_t LHS, + const std::unique_ptr &RHS) const { return LHS < RHS->getOffset(); } }; @@ -393,10 +388,10 @@ namespace { DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) { parseCompileUnits(); - DWARFCompileUnit **CU = + std::unique_ptr *CU = std::lower_bound(CUs.begin(), CUs.end(), Offset, OffsetComparator()); if (CU != CUs.end()) { - return *CU; + return CU->get(); } return 0; } @@ -636,7 +631,7 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) : // Make data point to uncompressed section contents and save its contents. name = name.substr(1); data = UncompressedSection->getBuffer(); - UncompressedSections.push_back(UncompressedSection.release()); + UncompressedSections.push_back(std::move(UncompressedSection)); } StringRef *Section = @@ -755,8 +750,4 @@ DWARFContextInMemory::DWARFContextInMemory(object::ObjectFile *Obj) : } } -DWARFContextInMemory::~DWARFContextInMemory() { - DeleteContainerPointers(UncompressedSections); -} - void DWARFContextInMemory::anchor() { } diff --git a/lib/DebugInfo/DWARFContext.h b/lib/DebugInfo/DWARFContext.h index 42d34b18f46..a3bae792737 100644 --- a/lib/DebugInfo/DWARFContext.h +++ b/lib/DebugInfo/DWARFContext.h @@ -28,8 +28,8 @@ namespace llvm { /// information parsing. The actual data is supplied through pure virtual /// methods that a concrete implementation provides. class DWARFContext : public DIContext { - typedef SmallVector CUVector; - typedef SmallVector TUVector; + typedef SmallVector, 1> CUVector; + typedef SmallVector, 1> TUVector; CUVector CUs; TUVector TUs; @@ -69,7 +69,6 @@ public: }; DWARFContext() : DIContext(CK_DWARF) {} - virtual ~DWARFContext(); static bool classof(const DIContext *DICtx) { return DICtx->getKind() == CK_DWARF; @@ -131,13 +130,13 @@ public: /// Get the compile unit at the specified index for this compile unit. DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) { parseCompileUnits(); - return CUs[index]; + return CUs[index].get(); } /// Get the compile unit at the specified index for the DWO compile units. DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) { parseDWOCompileUnits(); - return DWOCUs[index]; + return DWOCUs[index].get(); } /// Get a pointer to the parsed DebugAbbrev object. @@ -237,11 +236,10 @@ class DWARFContextInMemory : public DWARFContext { StringRef RangeDWOSection; StringRef AddrSection; - SmallVector UncompressedSections; + SmallVector, 4> UncompressedSections; public: DWARFContextInMemory(object::ObjectFile *); - ~DWARFContextInMemory(); bool isLittleEndian() const override { return IsLittleEndian; } uint8_t getAddressSize() const override { return AddressSize; } const Section &getInfoSection() override { return InfoSection; }