[ELF] Use std::find_if instead

llvm-svn: 221426
This commit is contained in:
Shankar Easwaran 2014-11-06 02:03:35 +00:00
parent 37d1aa715a
commit 0c501df3de
2 changed files with 15 additions and 20 deletions

View File

@ -630,8 +630,6 @@ DefaultLayout<ELFT>::mergeSimilarSections() {
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) {

View File

@ -519,18 +519,17 @@ template <class ELFT> void Segment<ELFT>::assignVirtualAddress(uint64_t addr) {
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>::assignVirtualAddress(uint64_t addr) {
}
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);