[llvm-commits] CVS: llvm/lib/System/Win32/Path.inc Signals.inc
Reid Spencer
reid at x10sys.com
Thu Mar 29 12:06:31 PDT 2007
Changes in directory llvm/lib/System/Win32:
Path.inc updated: 1.62 -> 1.63
Signals.inc updated: 1.22 -> 1.23
---
Log message:
For PR789: http://llvm.org/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.
---
Diffs of the changes: (+18 -16)
Path.inc | 28 ++++++++++++++--------------
Signals.inc | 6 ++++--
2 files changed, 18 insertions(+), 16 deletions(-)
Index: llvm/lib/System/Win32/Path.inc
diff -u llvm/lib/System/Win32/Path.inc:1.62 llvm/lib/System/Win32/Path.inc:1.63
--- llvm/lib/System/Win32/Path.inc:1.62 Thu Mar 29 12:27:38 2007
+++ llvm/lib/System/Win32/Path.inc Thu Mar 29 14:05:44 2007
@@ -306,13 +306,15 @@
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 @@
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::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 @@
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 @@
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;
Index: llvm/lib/System/Win32/Signals.inc
diff -u llvm/lib/System/Win32/Signals.inc:1.22 llvm/lib/System/Win32/Signals.inc:1.23
--- llvm/lib/System/Win32/Signals.inc:1.22 Fri Aug 25 16:37:17 2006
+++ llvm/lib/System/Win32/Signals.inc Thu Mar 29 14:05:44 2007
@@ -101,8 +101,10 @@
// 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;
More information about the llvm-commits
mailing list