[lld] 7c269db - [lld-macho] Simplify DeduplicatedCStringSection::finalizeContents. NFC
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 14 13:13:05 PST 2022
Author: Fangrui Song
Date: 2022-01-14T13:12:57-08:00
New Revision: 7c269db779ff3950bac2e25ea78b14b4e2b8b247
URL: https://github.com/llvm/llvm-project/commit/7c269db779ff3950bac2e25ea78b14b4e2b8b247
DIFF: https://github.com/llvm/llvm-project/commit/7c269db779ff3950bac2e25ea78b14b4e2b8b247.diff
LOG: [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
Added:
Modified:
lld/MachO/SyntheticSections.cpp
Removed:
################################################################################
diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp
index 0fa91d67f913e..23e908646d000 100644
--- a/lld/MachO/SyntheticSections.cpp
+++ b/lld/MachO/SyntheticSections.cpp
@@ -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));
+ isec->pieces[i].outSecOff =
+ builder.add(isec->getCachedHashStringRef(i));
+ isec->isFinal = true;
+ }
- // 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;
- }
- }
}
// This section is actually emitted as __TEXT,__const by ld64, but clang may
More information about the llvm-commits
mailing list