summaryrefslogtreecommitdiff
path: root/lib/System/Win32
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-03-29 19:05:44 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-03-29 19:05:44 +0000
commit8475ec068c213d0bf73f7686d82491a8f12e3b32 (patch)
treeb455b532bbe4b9a50f4baadecf4a48d83fc801a6 /lib/System/Win32
parentf735f7b3ac424bd701af2da2e3d4b69fbcb2b203 (diff)
downloadllvm-8475ec068c213d0bf73f7686d82491a8f12e3b32.tar.gz
llvm-8475ec068c213d0bf73f7686d82491a8f12e3b32.tar.bz2
llvm-8475ec068c213d0bf73f7686d82491a8f12e3b32.tar.xz
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
Diffstat (limited to 'lib/System/Win32')
-rw-r--r--lib/System/Win32/Path.inc28
-rw-r--r--lib/System/Win32/Signals.inc6
2 files changed, 18 insertions, 16 deletions
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
index 5bb2e39e94..57d75358b8 100644
--- a/lib/System/Win32/Path.inc
+++ b/lib/System/Win32/Path.inc
@@ -306,13 +306,15 @@ Path::getLast() const {
return path.substr(pos+1);
}
-bool
-Path::getFileStatus(FileStatus &info, bool update, std::string *ErrStr) const {
+const FileStatus *
+Path::getFileStatus(bool update, std::string *ErrStr) const {
if (status == 0 || update) {
WIN32_FILE_ATTRIBUTE_DATA fi;
- if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
- return MakeErrMsg(ErrStr, "getStatusInfo():" + std::string(path) +
+ if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi)) {
+ MakeErrMsg(ErrStr, "getStatusInfo():" + std::string(path) +
": Can't get status: ");
+ return 0;
+ }
if (status == 0)
status = new FileStatus;
@@ -337,8 +339,7 @@ Path::getFileStatus(FileStatus &info, bool update, std::string *ErrStr) const {
status->isDir = fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
}
- info = *status;
- return false;
+ return status;
}
bool Path::makeReadableOnDisk(std::string* ErrMsg) {
@@ -369,11 +370,10 @@ bool Path::makeExecutableOnDisk(std::string* ErrMsg) {
bool
Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const {
- FileStatus Status;
- if (getFileStatus(Status, ErrMsg))
+ const FileStatus *Status = getFileStatus(false, ErrMsg);
+ if (!Status)
return true;
-
- if (!Status.isDir) {
+ if (!Status->isDir) {
MakeErrMsg(ErrMsg, path + ": not a directory");
return true;
}
@@ -567,11 +567,11 @@ Path::createFileOnDisk(std::string* ErrMsg) {
bool
Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
- FileStatus Status;
- if (getFileStatus(Status, ErrStr))
+ const FileStatus *Status = getFileStatus(false, ErrStr);
+ if (!Status)
return false;
- if (Status.isFile) {
+ if (Status->isFile) {
DWORD attr = GetFileAttributes(path.c_str());
// If it doesn't exist, we're done.
@@ -588,7 +588,7 @@ Path::eraseFromDisk(bool remove_contents, std::string *ErrStr) const {
if (!DeleteFile(path.c_str()))
return MakeErrMsg(ErrStr, path + ": Can't destroy file: ");
return false;
- } else if (Status.isDir) {
+ } else if (Status->isDir) {
// If it doesn't exist, we're done.
if (!exists())
return false;
diff --git a/lib/System/Win32/Signals.inc b/lib/System/Win32/Signals.inc
index 0c93b228c3..8adf7674fa 100644
--- a/lib/System/Win32/Signals.inc
+++ b/lib/System/Win32/Signals.inc
@@ -101,8 +101,10 @@ bool sys::RemoveFileOnSignal(const sys::Path &Filename, std::string* ErrMsg) {
// RemoveDirectoryOnSignal - The public API
bool sys::RemoveDirectoryOnSignal(const sys::Path& path, std::string* ErrMsg) {
// Not a directory?
- sys::FileStatus Status;
- if (path.getFileStatus(Status) || !Status.isDir) {
+ const sys::FileStatus *Status = path.getFileStatus(false, ErrMsg);
+ if (!Status)
+ return true;
+ if (!Status->isDir) {
if (ErrMsg)
*ErrMsg = path.toString() + " is not a directory";
return true;