forked from OSchip/llvm-project
[LLD][COFF] Avoid std::vector resizes during type merging
Consistently saves approx. 0.6 sec (out of 18 sec) on a large output (400 MB EXE, 2 GB PDB). Differential Revision: https://reviews.llvm.org/D94555
This commit is contained in:
parent
3bd620d450
commit
e7a371f9fd
|
@ -679,6 +679,26 @@ void TpiSource::mergeUniqueTypeRecords(ArrayRef<uint8_t> typeRecords,
|
||||||
auto nextUniqueIndex = uniqueTypes.begin();
|
auto nextUniqueIndex = uniqueTypes.begin();
|
||||||
assert(mergedTpi.recs.empty());
|
assert(mergedTpi.recs.empty());
|
||||||
assert(mergedIpi.recs.empty());
|
assert(mergedIpi.recs.empty());
|
||||||
|
|
||||||
|
// Pre-compute the number of elements in advance to avoid std::vector resizes.
|
||||||
|
unsigned nbTpiRecs = 0;
|
||||||
|
unsigned nbIpiRecs = 0;
|
||||||
|
forEachTypeChecked(typeRecords, [&](const CVType &ty) {
|
||||||
|
if (nextUniqueIndex != uniqueTypes.end() &&
|
||||||
|
*nextUniqueIndex == ghashIndex) {
|
||||||
|
assert(ty.length() <= codeview::MaxRecordLength);
|
||||||
|
size_t newSize = alignTo(ty.length(), 4);
|
||||||
|
(isIdRecord(ty.kind()) ? nbIpiRecs : nbTpiRecs) += newSize;
|
||||||
|
++nextUniqueIndex;
|
||||||
|
}
|
||||||
|
++ghashIndex;
|
||||||
|
});
|
||||||
|
mergedTpi.recs.reserve(nbTpiRecs);
|
||||||
|
mergedIpi.recs.reserve(nbIpiRecs);
|
||||||
|
|
||||||
|
// Do the actual type merge.
|
||||||
|
ghashIndex = 0;
|
||||||
|
nextUniqueIndex = uniqueTypes.begin();
|
||||||
forEachTypeChecked(typeRecords, [&](const CVType &ty) {
|
forEachTypeChecked(typeRecords, [&](const CVType &ty) {
|
||||||
if (nextUniqueIndex != uniqueTypes.end() &&
|
if (nextUniqueIndex != uniqueTypes.end() &&
|
||||||
*nextUniqueIndex == ghashIndex) {
|
*nextUniqueIndex == ghashIndex) {
|
||||||
|
|
Loading…
Reference in New Issue