Skip to content

Commit b1957e7

Browse files
committed
std::vector<SecPtr>::iterator -> SecPtr&
1 parent 2860c31 commit b1957e7

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

llvm/lib/ObjCopy/ELF/ELFObject.cpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,27 +2154,25 @@ ELFWriter<ELFT>::ELFWriter(Object &Obj, raw_ostream &Buf, bool WSH,
21542154
: Writer(Obj, Buf), WriteSectionHeaders(WSH && Obj.HadShdrs),
21552155
OnlyKeepDebug(OnlyKeepDebug) {}
21562156

2157-
Error Object::updateSectionData(std::vector<SecPtr>::iterator It,
2158-
ArrayRef<uint8_t> Data) {
2159-
auto *OldSec = It->get();
2160-
if (!OldSec->hasContents())
2157+
Error Object::updateSectionData(SecPtr &Sec, ArrayRef<uint8_t> Data) {
2158+
if (!Sec->hasContents())
21612159
return createStringError(
21622160
errc::invalid_argument,
21632161
"section '%s' cannot be updated because it does not have contents",
2164-
OldSec->Name.c_str());
2162+
Sec->Name.c_str());
21652163

2166-
if (Data.size() > OldSec->Size && OldSec->ParentSegment)
2164+
if (Data.size() > Sec->Size && Sec->ParentSegment)
21672165
return createStringError(errc::invalid_argument,
21682166
"cannot fit data of size %zu into section '%s' "
21692167
"with size %" PRIu64 " that is part of a segment",
2170-
Data.size(), OldSec->Name.c_str(), OldSec->Size);
2168+
Data.size(), Sec->Name.c_str(), Sec->Size);
21712169

2172-
if (!OldSec->ParentSegment) {
2173-
*It = std::make_unique<OwnedDataSection>(*OldSec, Data);
2170+
if (!Sec->ParentSegment) {
2171+
Sec = std::make_unique<OwnedDataSection>(*Sec, Data);
21742172
} else {
21752173
// The segment writer will be in charge of updating these contents.
2176-
OldSec->Size = Data.size();
2177-
UpdatedSections[OldSec] = Data;
2174+
Sec->Size = Data.size();
2175+
UpdatedSections[Sec.get()] = Data;
21782176
}
21792177

21802178
return Error::success();
@@ -2186,14 +2184,14 @@ Error Object::updateSection(StringRef Name, ArrayRef<uint8_t> Data) {
21862184
if (It == Sections.end())
21872185
return createStringError(errc::invalid_argument, "section '%s' not found",
21882186
Name.str().c_str());
2189-
return updateSectionData(It, Data);
2187+
return updateSectionData(*It, Data);
21902188
}
21912189

21922190
Error Object::updateSectionData(SectionBase &S, ArrayRef<uint8_t> Data) {
21932191
auto It = llvm::find_if(Sections,
21942192
[&](const SecPtr &Sec) { return Sec.get() == &S; });
21952193
assert(It != Sections.end() && "The section should belong to the object");
2196-
return updateSectionData(It, Data);
2194+
return updateSectionData(*It, Data);
21972195
}
21982196

21992197
Error Object::removeSections(

llvm/lib/ObjCopy/ELF/ELFObject.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,8 +1168,7 @@ class Object {
11681168
return Sec.Flags & ELF::SHF_ALLOC;
11691169
};
11701170

1171-
Error updateSectionData(std::vector<SecPtr>::iterator SecIt,
1172-
ArrayRef<uint8_t> Data);
1171+
Error updateSectionData(SecPtr &Sec, ArrayRef<uint8_t> Data);
11731172

11741173
public:
11751174
template <class T>

0 commit comments

Comments
 (0)