From 8475ec068c213d0bf73f7686d82491a8f12e3b32 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Thu, 29 Mar 2007 19:05:44 +0000 Subject: For PR789: Make the sys::Path::getFileStatus function more efficient by having it return a pointer to the FileStatus structure rather than copy it. Adjust uses of the function accordingly. Also, fix some memory issues in sys::Path. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35476 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/llvm-ar/llvm-ar.cpp | 32 ++++++++++++++++---------------- tools/llvm-db/Commands.cpp | 6 +++--- tools/llvmc/CompilerDriver.cpp | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) (limited to 'tools') diff --git a/tools/llvm-ar/llvm-ar.cpp b/tools/llvm-ar/llvm-ar.cpp index ea3a59b..649eb7a 100644 --- a/tools/llvm-ar/llvm-ar.cpp +++ b/tools/llvm-ar/llvm-ar.cpp @@ -281,16 +281,16 @@ recurseDirectories(const sys::Path& path, for (std::set::iterator I = content.begin(), E = content.end(); I != E; ++I) { // Make sure it exists and is a directory - sys::FileStatus Status; - if (I->getFileStatus(Status)) { - if (Status.isDir) { - std::set moreResults; - if (recurseDirectories(*I, moreResults, ErrMsg)) - return true; - result.insert(moreResults.begin(), moreResults.end()); - } else { + const sys::FileStatus *Status = I->getFileStatus(false, ErrMsg); + if (!Status) + return true; + if (Status->isDir) { + std::set moreResults; + if (recurseDirectories(*I, moreResults, ErrMsg)) + return true; + result.insert(moreResults.begin(), moreResults.end()); + } else { result.insert(*I); - } } } } @@ -308,11 +308,11 @@ bool buildPaths(bool checkExistence, std::string* ErrMsg) { if (checkExistence) { if (!aPath.exists()) throw std::string("File does not exist: ") + Members[i]; - sys::FileStatus si; std::string Err; - if (aPath.getFileStatus(si, false, &Err)) + const sys::FileStatus *si = aPath.getFileStatus(false, &Err); + if (!si) throw Err; - if (si.isDir) { + if (si->isDir) { std::set dirpaths; if (recurseDirectories(aPath, dirpaths, ErrMsg)) return true; @@ -644,14 +644,14 @@ doReplaceOrInsert(std::string* ErrMsg) { } if (found != remaining.end()) { - sys::FileStatus si; std::string Err; - if (found->getFileStatus(si, false, &Err)) + const sys::FileStatus *si = found->getFileStatus(false, &Err); + if (!si) return true; - if (si.isDir) { + if (si->isDir) { if (OnlyUpdate) { // Replace the item only if it is newer. - if (si.modTime > I->getModTime()) + if (si->modTime > I->getModTime()) if (I->replaceWith(*found, ErrMsg)) return true; } else { diff --git a/tools/llvm-db/Commands.cpp b/tools/llvm-db/Commands.cpp index da07769..5a8aa2f 100644 --- a/tools/llvm-db/Commands.cpp +++ b/tools/llvm-db/Commands.cpp @@ -50,11 +50,11 @@ void CLIDebugger::startProgramRunning() { // If the program has been modified, reload it! sys::Path Program(Dbg.getProgramPath()); - sys::FileStatus Status; std::string Err; - if (Program.getFileStatus(Status, &Err)) + const sys::FileStatus *Status = Program.getFileStatus(false, &Err); + if (!Status) throw Err; - if (TheProgramInfo->getProgramTimeStamp() != Status.getTimestamp()) { + if (TheProgramInfo->getProgramTimeStamp() != Status->getTimestamp()) { std::cout << "'" << Program << "' has changed; re-reading program.\n"; // Unload an existing program. This kills the program if necessary. diff --git a/tools/llvmc/CompilerDriver.cpp b/tools/llvmc/CompilerDriver.cpp index c153df8..3d91ad9 100644 --- a/tools/llvmc/CompilerDriver.cpp +++ b/tools/llvmc/CompilerDriver.cpp @@ -195,8 +195,8 @@ private: void cleanup() { if (!isSet(KEEP_TEMPS_FLAG)) { - sys::FileStatus Status; - if (!TempDir.getFileStatus(Status) && Status.isDir) + const sys::FileStatus *Status = TempDir.getFileStatus(); + if (Status && Status->isDir) TempDir.eraseFromDisk(/*remove_contents=*/true); } else { std::cout << "Temporary files are in " << TempDir << "\n"; -- cgit v1.1