summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2017-12-07 18:46:03 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2017-12-07 18:46:03 +0000
commit50ca10bb584d5994726e547aac215771315069c4 (patch)
treec40cc97ed056ea84fd673b8bff99bca5eef89bf1
parent6cfc1368704d403d7be9136ac1561eff43d387d5 (diff)
downloadbcm5719-llvm-50ca10bb584d5994726e547aac215771315069c4.tar.gz
bcm5719-llvm-50ca10bb584d5994726e547aac215771315069c4.zip
Avoid using a temporary std::vector.
With this memory usage when linking clang goes from 174.62MB to 172.77MB. llvm-svn: 320069
-rw-r--r--lld/ELF/SyntheticSections.cpp30
1 files changed, 15 insertions, 15 deletions
diff --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 6b82dbdd717..a75aaca04bb 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -1747,29 +1747,29 @@ void GnuHashTableSection::writeBloomFilter(uint8_t *Buf) {
}
void GnuHashTableSection::writeHashTable(uint8_t *Buf) {
- // Group symbols by hash value.
- std::vector<std::vector<Entry>> Syms(NBuckets);
- for (const Entry &Ent : Symbols)
- Syms[Ent.BucketIdx].push_back(Ent);
-
// Write hash buckets. Hash buckets contain indices in the following
// hash value table.
uint32_t *Buckets = reinterpret_cast<uint32_t *>(Buf);
- for (size_t I = 0; I < NBuckets; ++I)
- if (!Syms[I].empty())
- write32(Buckets + I, Syms[I][0].Sym->DynsymIndex);
+ auto SymI = Symbols.begin();
+ for (size_t I = 0; I < NBuckets; ++I) {
+ auto NewI = std::find_if(SymI, Symbols.end(), [=](const Entry &Ent) {
+ return Ent.BucketIdx == I;
+ });
+ if (NewI != Symbols.end()) {
+ write32(Buckets + I, NewI->Sym->DynsymIndex);
+ SymI = NewI;
+ }
+ }
// Write a hash value table. It represents a sequence of chains that
// share the same hash modulo value. The last element of each chain
// is terminated by LSB 1.
uint32_t *Values = Buckets + NBuckets;
- size_t I = 0;
- for (std::vector<Entry> &Vec : Syms) {
- if (Vec.empty())
- continue;
- for (const Entry &Ent : makeArrayRef(Vec).drop_back())
- write32(Values + I++, Ent.Hash & ~1);
- write32(Values + I++, Vec.back().Hash | 1);
+ for (auto I = Symbols.begin(), E = Symbols.end(); I != E; ++I) {
+ uint32_t Hash = I->Hash;
+ bool IsLastInChain = (I + 1) == E || I->BucketIdx != (I + 1)->BucketIdx;
+ Hash = IsLastInChain ? Hash | 1 : Hash & ~1;
+ write32(Values++, Hash);
}
}
OpenPOWER on IntegriCloud