From 1de14dd6f255274ba806d4bf0d76a1e121c9b2d3 Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Wed, 10 Feb 2016 21:32:24 +0000 Subject: [PATCH] Use ArrayRef instead of deep copies of CompactUnwindEntries. NFC. We have a vector of all of the compact unwind entries anyway, and its live as long as we need it to be. So instead of copying from that vector to another, just take references to the range of the original vector we need for each compact unwind page. llvm-svn: 260437 --- lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp b/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp index 2e6ac0d..68cf1b9 100644 --- a/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp +++ b/lld/lib/ReaderWriter/MachO/CompactUnwindPass.cpp @@ -59,7 +59,7 @@ struct CompactUnwindEntry { }; struct UnwindInfoPage { - std::vector entries; + ArrayRef entries; }; } @@ -179,7 +179,7 @@ public: } // Finally, write out the final sentinel index - CompactUnwindEntry &finalEntry = pages[pages.size() - 1].entries.back(); + auto &finalEntry = pages[pages.size() - 1].entries.back(); addImageReference(_topLevelIndexOffset + 3 * pages.size() * sizeof(uint32_t), finalEntry.rangeStart, finalEntry.rangeLength); @@ -323,26 +323,23 @@ private: // boundaries. That might be worth doing, or perhaps we could perform some // minor balancing for expected number of lookups. std::vector pages; - unsigned pageStart = 0; + auto remainingInfos = llvm::makeArrayRef(unwindInfos); do { pages.push_back(UnwindInfoPage()); // FIXME: we only create regular pages at the moment. These can hold up to // 1021 entries according to the documentation. - unsigned entriesInPage = - std::min(1021U, (unsigned)unwindInfos.size() - pageStart); + unsigned entriesInPage = std::min(1021U, (unsigned)remainingInfos.size()); - std::copy(unwindInfos.begin() + pageStart, - unwindInfos.begin() + pageStart + entriesInPage, - std::back_inserter(pages.back().entries)); - pageStart += entriesInPage; + pages.back().entries = remainingInfos.slice(0, entriesInPage); + remainingInfos = remainingInfos.slice(entriesInPage); DEBUG(llvm::dbgs() << " Page from " << pages.back().entries[0].rangeStart->name() << " to " << pages.back().entries.back().rangeStart->name() << " + " << llvm::format("0x%x", pages.back().entries.back().rangeLength) << " has " << entriesInPage << " entries\n"); - } while (pageStart < unwindInfos.size()); + } while (!remainingInfos.empty()); auto *unwind = new (_file.allocator()) UnwindInfoAtom(_archHandler, _file, _isBig, personalities, -- 2.7.4