[lld-macho] Simplify DeduplicatedCStringSection::finalizeContents. NFC

Tail merge is slow and of low value. With regular string deduplication, we can
just use the return value of StringTableBuilder::add.

There is no noticeable performance increase because without deduplication
`__cstring` is quite small (7.6MiB for chromium_framework).

Reviewed By: #lld-macho, Jez Ng

Differential Revision: https://reviews.llvm.org/D117273
This commit is contained in:
Fangrui Song 2022-01-14 13:12:57 -08:00
parent 6cacd420a1
commit 7c269db779
1 changed files with 6 additions and 17 deletions

View File

@ -1379,26 +1379,15 @@ DeduplicatedCStringSection::DeduplicatedCStringSection()
void DeduplicatedCStringSection::finalizeContents() {
// Add all string pieces to the string table builder to create section
// contents.
for (const CStringInputSection *isec : inputs)
for (CStringInputSection *isec : inputs) {
for (size_t i = 0, e = isec->pieces.size(); i != e; ++i)
if (isec->pieces[i].live)
builder.add(isec->getCachedHashStringRef(i));
// Fix the string table content. After this, the contents will never change.
builder.finalizeInOrder();
// finalize() fixed tail-optimized strings, so we can now get
// offsets of strings. Get an offset for each string and save it
// to a corresponding SectionPiece for easy access.
for (CStringInputSection *isec : inputs) {
for (size_t i = 0, e = isec->pieces.size(); i != e; ++i) {
if (!isec->pieces[i].live)
continue;
isec->pieces[i].outSecOff =
builder.getOffset(isec->getCachedHashStringRef(i));
isec->isFinal = true;
}
isec->pieces[i].outSecOff =
builder.add(isec->getCachedHashStringRef(i));
isec->isFinal = true;
}
builder.finalizeInOrder();
}
// This section is actually emitted as __TEXT,__const by ld64, but clang may