Inline MergeInputSection::getData().

This change seems to make LLD 0.6% faster when linking Clang with
debug info. I don't want us to have lots of local optimizations,
but this function is very hot, and the improvement is small but
not negligible, so I think it's worth doing.

llvm-svn: 288757
This commit is contained in:
Rui Ueyama 2016-12-06 02:19:30 +00:00
parent a7f30b1af1
commit c8e6884871
2 changed files with 15 additions and 11 deletions

View File

@ -719,16 +719,6 @@ void MergeInputSection<ELFT>::splitStrings(ArrayRef<uint8_t> Data,
}
}
// Returns I'th piece's data.
template <class ELFT>
CachedHashStringRef MergeInputSection<ELFT>::getData(size_t I) const {
size_t End =
(Pieces.size() - 1 == I) ? this->Data.size() : Pieces[I + 1].InputOff;
const SectionPiece &P = Pieces[I];
StringRef S = toStringRef(this->Data.slice(P.InputOff, End - P.InputOff));
return {S, Hashes[I]};
}
// Split non-SHF_STRINGS section. Such section is a sequence of
// fixed size records.
template <class ELFT>

View File

@ -194,7 +194,21 @@ public:
// Splittable sections are handled as a sequence of data
// rather than a single large blob of data.
std::vector<SectionPiece> Pieces;
llvm::CachedHashStringRef getData(size_t Idx) const;
// Returns I'th piece's data. This function is very hot when
// string merging is enabled, so we want to inline.
LLVM_ATTRIBUTE_ALWAYS_INLINE
llvm::CachedHashStringRef getData(size_t I) const {
size_t Begin = Pieces[I].InputOff;
size_t End;
if (Pieces.size() - 1 == I)
End = this->Data.size();
else
End = Pieces[I + 1].InputOff;
StringRef S = {(const char *)(this->Data.data() + Begin), End - Begin};
return {S, Hashes[I]};
}
// Returns the SectionPiece at a given input section offset.
SectionPiece *getSectionPiece(uintX_t Offset);