[lld] r221426 - [ELF] Use std::find_if instead
Shankar Easwaran
shankarke at gmail.com
Wed Nov 5 18:03:36 PST 2014
Author: shankare
Date: Wed Nov 5 20:03:35 2014
New Revision: 221426
URL: http://llvm.org/viewvc/llvm-project?rev=221426&view=rev
Log:
[ELF] Use std::find_if instead
Modified:
lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=221426&r1=221425&r2=221426&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Wed Nov 5 20:03:35 2014
@@ -630,8 +630,6 @@ DefaultLayout<ELFT>::mergeSimilarSection
template <class ELFT> void DefaultLayout<ELFT>::assignSectionsToSegments() {
ScopedTask task(getDefaultDomain(), "assignSectionsToSegments");
ELFLinkingContext::OutputMagic outputMagic = _context.getOutputMagic();
- // TODO: Do we want to give a chance for the targetHandlers
- // to sort segments in an arbitrary order?
// sort the sections by their order as defined by the layout
std::stable_sort(_sections.begin(), _sections.end(),
[](Chunk<ELFT> *A, Chunk<ELFT> *B) {
Modified: lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h?rev=221426&r1=221425&r2=221426&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/SegmentChunks.h Wed Nov 5 20:03:35 2014
@@ -519,18 +519,17 @@ template <class ELFT> void Segment<ELFT>
if (((newAddr - curAddr) > this->_context.getPageSize()) &&
(_outputMagic != ELFLinkingContext::OutputMagic::NMAGIC &&
_outputMagic != ELFLinkingContext::OutputMagic::OMAGIC)) {
- slice = nullptr;
- // TODO: use std::find here
- for (auto s : slices()) {
- if (s->startSection() == startSection) {
- slice = s;
- break;
- }
- }
- if (!slice) {
+ auto sliceIter =
+ std::find_if(_segmentSlices.begin(), _segmentSlices.end(),
+ [startSection](SegmentSlice<ELFT> *s) -> bool {
+ return s->startSection() == startSection;
+ });
+ if (sliceIter == _segmentSlices.end()) {
slice = new (_segmentAllocate.Allocate<SegmentSlice<ELFT>>())
SegmentSlice<ELFT>();
_segmentSlices.push_back(slice);
+ } else {
+ slice = (*sliceIter);
}
slice->setStart(startSection);
slice->setSections(make_range(startSectionIter, si));
@@ -573,18 +572,16 @@ template <class ELFT> void Segment<ELFT>
}
currSection++;
}
- slice = nullptr;
- for (auto s : slices()) {
- // TODO: add std::find
- if (s->startSection() == startSection) {
- slice = s;
- break;
- }
- }
- if (!slice) {
+ auto sliceIter = std::find_if(_segmentSlices.begin(), _segmentSlices.end(),
+ [startSection](SegmentSlice<ELFT> *s) -> bool {
+ return s->startSection() == startSection;
+ });
+ if (sliceIter == _segmentSlices.end()) {
slice = new (_segmentAllocate.Allocate<SegmentSlice<ELFT>>())
SegmentSlice<ELFT>();
_segmentSlices.push_back(slice);
+ } else {
+ slice = (*sliceIter);
}
slice->setStart(startSection);
slice->setVirtualAddr(curSliceAddress);
More information about the llvm-commits
mailing list