1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

Only seek once before writing the member offsets.

This cuts down the number on system calls done by a static llvm-ar producing
lib/libclangSema.a from 9164 to 442.

llvm-svn: 224025
This commit is contained in:
Rafael Espindola 2014-12-11 16:34:00 +00:00
parent c0790c762d
commit c3e0e956cb

View File

@ -685,10 +685,11 @@ static void writeStringTable(raw_fd_ostream &Out,
Out.seek(Pos); Out.seek(Pos);
} }
static void // Returns the offset of the first reference to a member offset.
writeSymbolTable(raw_fd_ostream &Out, ArrayRef<NewArchiveIterator> Members, static unsigned writeSymbolTable(raw_fd_ostream &Out,
ArrayRef<MemoryBufferRef> Buffers, ArrayRef<NewArchiveIterator> Members,
std::vector<std::pair<unsigned, unsigned>> &MemberOffsetRefs) { ArrayRef<MemoryBufferRef> Buffers,
std::vector<unsigned> &MemberOffsetRefs) {
unsigned StartOffset = 0; unsigned StartOffset = 0;
unsigned MemberNum = 0; unsigned MemberNum = 0;
std::string NameBuf; std::string NameBuf;
@ -723,14 +724,14 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef<NewArchiveIterator> Members,
failIfError(S.printName(NameOS)); failIfError(S.printName(NameOS));
NameOS << '\0'; NameOS << '\0';
++NumSyms; ++NumSyms;
MemberOffsetRefs.push_back(std::make_pair(Out.tell(), MemberNum)); MemberOffsetRefs.push_back(MemberNum);
print32BE(Out, 0); print32BE(Out, 0);
} }
} }
Out << NameOS.str(); Out << NameOS.str();
if (StartOffset == 0) if (StartOffset == 0)
return; return 0;
if (Out.tell() % 2) if (Out.tell() % 2)
Out << '\0'; Out << '\0';
@ -741,6 +742,7 @@ writeSymbolTable(raw_fd_ostream &Out, ArrayRef<NewArchiveIterator> Members,
Out.seek(StartOffset); Out.seek(StartOffset);
print32BE(Out, NumSyms); print32BE(Out, NumSyms);
Out.seek(Pos); Out.seek(Pos);
return StartOffset + 4;
} }
static void static void
@ -755,7 +757,7 @@ performWriteOperation(ArchiveOperation Operation, object::Archive *OldArchive,
raw_fd_ostream &Out = Output.os(); raw_fd_ostream &Out = Output.os();
Out << "!<arch>\n"; Out << "!<arch>\n";
std::vector<std::pair<unsigned, unsigned> > MemberOffsetRefs; std::vector<unsigned> MemberOffsetRefs;
std::vector<std::unique_ptr<MemoryBuffer>> Buffers; std::vector<std::unique_ptr<MemoryBuffer>> Buffers;
std::vector<MemoryBufferRef> Members; std::vector<MemoryBufferRef> Members;
@ -787,31 +789,25 @@ performWriteOperation(ArchiveOperation Operation, object::Archive *OldArchive,
Members.push_back(MemberRef); Members.push_back(MemberRef);
} }
unsigned MemberReferenceOffset = 0;
if (Symtab) { if (Symtab) {
writeSymbolTable(Out, NewMembers, Members, MemberOffsetRefs); MemberReferenceOffset =
writeSymbolTable(Out, NewMembers, Members, MemberOffsetRefs);
} }
std::vector<unsigned> StringMapIndexes; std::vector<unsigned> StringMapIndexes;
writeStringTable(Out, NewMembers, StringMapIndexes); writeStringTable(Out, NewMembers, StringMapIndexes);
std::vector<std::pair<unsigned, unsigned> >::iterator MemberRefsI =
MemberOffsetRefs.begin();
unsigned MemberNum = 0; unsigned MemberNum = 0;
unsigned LongNameMemberNum = 0; unsigned LongNameMemberNum = 0;
unsigned NewMemberNum = 0; unsigned NewMemberNum = 0;
std::vector<unsigned> MemberOffset;
for (std::vector<NewArchiveIterator>::iterator I = NewMembers.begin(), for (std::vector<NewArchiveIterator>::iterator I = NewMembers.begin(),
E = NewMembers.end(); E = NewMembers.end();
I != E; ++I, ++MemberNum) { I != E; ++I, ++MemberNum) {
unsigned Pos = Out.tell(); unsigned Pos = Out.tell();
while (MemberRefsI != MemberOffsetRefs.end() && MemberOffset.push_back(Pos);
MemberRefsI->second == MemberNum) {
Out.seek(MemberRefsI->first);
print32BE(Out, Pos);
++MemberRefsI;
}
Out.seek(Pos);
MemoryBufferRef File = Members[MemberNum]; MemoryBufferRef File = Members[MemberNum];
if (I->isNewMember()) { if (I->isNewMember()) {
@ -850,6 +846,12 @@ performWriteOperation(ArchiveOperation Operation, object::Archive *OldArchive,
Out << '\n'; Out << '\n';
} }
if (MemberReferenceOffset) {
Out.seek(MemberReferenceOffset);
for (unsigned MemberNum : MemberOffsetRefs)
print32BE(Out, MemberOffset[MemberNum]);
}
Output.keep(); Output.keep();
Out.close(); Out.close();
sys::fs::rename(TemporaryOutput, ArchiveName); sys::fs::rename(TemporaryOutput, ArchiveName);