From ba7661d2946d1603cf32dcce9cd82ce948b83c62 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Wed, 15 Jul 2015 22:46:53 +0000 Subject: [PATCH] For new archive member we only need to store the full path. We were storing both the path and the file name, which was redundant and easy to get confused up with. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242347 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Object/ArchiveWriter.h | 4 +--- lib/LibDriver/LibDriver.cpp | 3 +-- lib/Object/ArchiveWriter.cpp | 8 ++++---- tools/llvm-ar/llvm-ar.cpp | 16 +++++++--------- 4 files changed, 13 insertions(+), 18 deletions(-) diff --git a/include/llvm/Object/ArchiveWriter.h b/include/llvm/Object/ArchiveWriter.h index 9d1dd61bf66..fc4669de1ba 100644 --- a/include/llvm/Object/ArchiveWriter.h +++ b/include/llvm/Object/ArchiveWriter.h @@ -26,11 +26,9 @@ class NewArchiveIterator { object::Archive::child_iterator OldI; - StringRef NewFilename; - public: NewArchiveIterator(object::Archive::child_iterator I, StringRef Name); - NewArchiveIterator(StringRef I, StringRef Name); + NewArchiveIterator(StringRef FileName); bool isNewMember() const; StringRef getName() const; diff --git a/lib/LibDriver/LibDriver.cpp b/lib/LibDriver/LibDriver.cpp index 98148750204..17680e3b3bb 100644 --- a/lib/LibDriver/LibDriver.cpp +++ b/lib/LibDriver/LibDriver.cpp @@ -135,8 +135,7 @@ int llvm::libDriverMain(llvm::ArrayRef ArgsArr) { llvm::errs() << Arg->getValue() << ": no such file or directory\n"; return 1; } - Members.emplace_back(Saver.save(*Path), - llvm::sys::path::filename(Arg->getValue())); + Members.emplace_back(Saver.save(*Path)); } std::pair Result = diff --git a/lib/Object/ArchiveWriter.cpp b/lib/Object/ArchiveWriter.cpp index b555b8cfdcf..2aa481381df 100644 --- a/lib/Object/ArchiveWriter.cpp +++ b/lib/Object/ArchiveWriter.cpp @@ -38,8 +38,8 @@ NewArchiveIterator::NewArchiveIterator(object::Archive::child_iterator I, StringRef Name) : IsNewMember(false), Name(Name), OldI(I) {} -NewArchiveIterator::NewArchiveIterator(StringRef NewFilename, StringRef Name) - : IsNewMember(true), Name(Name), NewFilename(NewFilename) {} +NewArchiveIterator::NewArchiveIterator(StringRef FileName) + : IsNewMember(true), Name(FileName) {} StringRef NewArchiveIterator::getName() const { return Name; } @@ -52,14 +52,14 @@ object::Archive::child_iterator NewArchiveIterator::getOld() const { StringRef NewArchiveIterator::getNew() const { assert(IsNewMember); - return NewFilename; + return Name; } llvm::ErrorOr NewArchiveIterator::getFD(sys::fs::file_status &NewStatus) const { assert(IsNewMember); int NewFD; - if (auto EC = sys::fs::openFileForRead(NewFilename, NewFD)) + if (auto EC = sys::fs::openFileForRead(Name, NewFD)) return EC; assert(NewFD != -1); diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index 92f272dfad1..ec3cfcb5cad 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -437,8 +437,8 @@ static void performReadOperation(ArchiveOperation Operation, } void addMember(std::vector &Members, StringRef FileName, - StringRef Name, int Pos = -1) { - NewArchiveIterator NI(FileName, Name); + int Pos = -1) { + NewArchiveIterator NI(FileName); if (Pos == -1) Members.push_back(NI); else @@ -544,7 +544,7 @@ computeNewArchiveMembers(ArchiveOperation Operation, addMember(Ret, Child, Name); break; case IA_AddNewMeber: - addMember(Ret, *MemberI, Name); + addMember(Ret, *MemberI); break; case IA_Delete: break; @@ -552,7 +552,7 @@ computeNewArchiveMembers(ArchiveOperation Operation, addMember(Moved, Child, Name); break; case IA_MoveNewMember: - addMember(Moved, *MemberI, Name); + addMember(Moved, *MemberI); break; } if (MemberI != Members.end()) @@ -572,12 +572,10 @@ computeNewArchiveMembers(ArchiveOperation Operation, assert(unsigned(InsertPos) <= Ret.size()); Ret.insert(Ret.begin() + InsertPos, Moved.begin(), Moved.end()); - Ret.insert(Ret.begin() + InsertPos, Members.size(), - NewArchiveIterator("", "")); + Ret.insert(Ret.begin() + InsertPos, Members.size(), NewArchiveIterator("")); int Pos = InsertPos; for (auto &Member : Members) { - StringRef Name = sys::path::filename(Member); - addMember(Ret, Member, Name, Pos); + addMember(Ret, Member, Pos); ++Pos; } @@ -736,7 +734,7 @@ static void runMRIScript() { break; } case MRICommand::AddMod: - addMember(NewMembers, Rest, sys::path::filename(Rest)); + addMember(NewMembers, Rest); break; case MRICommand::Create: Create = true; -- 2.34.1