llvm.org GIT mirror llvm / 1fa0164
llvm-ar: close input files early. We already have them mapped into memory, so we can just close the file. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224020 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
1 changed file(s) with 13 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
412412 object::Archive::child_iterator OldI;
413413
414414 StringRef NewFilename;
415 mutable int NewFD;
416 mutable sys::fs::file_status NewStatus;
417415
418416 public:
419417 NewArchiveIterator(object::Archive::child_iterator I, StringRef Name);
425423 object::Archive::child_iterator getOld() const;
426424
427425 StringRef getNew() const;
428 int getFD() const;
426 int getFD(sys::fs::file_status &NewStatus) const;
429427 const sys::fs::file_status &getStatus() const;
430428 };
431429 }
437435 : IsNewMember(false), Name(Name), OldI(I) {}
438436
439437 NewArchiveIterator::NewArchiveIterator(StringRef NewFilename, StringRef Name)
440 : IsNewMember(true), Name(Name), NewFilename(NewFilename), NewFD(-1) {}
438 : IsNewMember(true), Name(Name), NewFilename(NewFilename) {}
441439
442440 StringRef NewArchiveIterator::getName() const { return Name; }
443441
453451 return NewFilename;
454452 }
455453
456 int NewArchiveIterator::getFD() const {
454 int NewArchiveIterator::getFD(sys::fs::file_status &NewStatus) const {
457455 assert(IsNewMember);
458 if (NewFD != -1)
459 return NewFD;
456 int NewFD;
460457 failIfError(sys::fs::openFileForRead(NewFilename, NewFD), NewFilename);
461458 assert(NewFD != -1);
462459
469466 failIfError(make_error_code(errc::is_a_directory), NewFilename);
470467
471468 return NewFD;
472 }
473
474 const sys::fs::file_status &NewArchiveIterator::getStatus() const {
475 assert(IsNewMember);
476 assert(NewFD != -1 && "Must call getFD first");
477 return NewStatus;
478469 }
479470
480471 template
767758
768759 std::vector> Buffers;
769760 std::vector Members;
761 std::vector NewMemberStatus;
770762
771763 for (unsigned I = 0, N = NewMembers.size(); I < N; ++I) {
772764 NewArchiveIterator &Member = NewMembers[I];
774766
775767 if (Member.isNewMember()) {
776768 StringRef Filename = Member.getNew();
777 int FD = Member.getFD();
778 const sys::fs::file_status &Status = Member.getStatus();
769 NewMemberStatus.resize(NewMemberStatus.size() + 1);
770 sys::fs::file_status &Status = NewMemberStatus.back();
771 int FD = Member.getFD(Status);
779772 ErrorOr> MemberBufferOrErr =
780773 MemoryBuffer::getOpenFile(FD, Filename, Status.getSize(), false);
781774 failIfError(MemberBufferOrErr.getError(), Filename);
775 if (close(FD) != 0)
776 fail("Could not close file");
782777 Buffers.push_back(std::move(MemberBufferOrErr.get()));
783778 MemberRef = Buffers.back()->getMemBufferRef();
784779 } else {
803798
804799 unsigned MemberNum = 0;
805800 unsigned LongNameMemberNum = 0;
801 unsigned NewMemberNum = 0;
806802 for (std::vector::iterator I = NewMembers.begin(),
807803 E = NewMembers.end();
808804 I != E; ++I, ++MemberNum) {
819815 MemoryBufferRef File = Members[MemberNum];
820816 if (I->isNewMember()) {
821817 StringRef FileName = I->getNew();
822 const sys::fs::file_status &Status = I->getStatus();
818 const sys::fs::file_status &Status = NewMemberStatus[NewMemberNum];
819 NewMemberNum++;
823820
824821 StringRef Name = sys::path::filename(FileName);
825822 if (Name.size() < 16)