summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2014-02-13 16:58:19 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2014-02-13 16:58:19 +0000
commitb6f72b240f3263675b7066b7278abe8fe0abc413 (patch)
tree85ed41a2ef514a8afc42c66898f046709ee1f0ee /llvm/lib/Support/Path.cpp
parentfbe5672746bed3920afc6265f5b8a0bce0f5e70b (diff)
downloadbcm5719-llvm-b6f72b240f3263675b7066b7278abe8fe0abc413.tar.gz
bcm5719-llvm-b6f72b240f3263675b7066b7278abe8fe0abc413.zip
Use mkdir instead of stat+mkdir.
This is an optimistic version of create_diretories: it tries to create the directory first and looks at the parent only if that fails. Running strace on "mkdir -p" shows that it is pessimistic, calling mkdir on every element of the path. We could implement that if needed. In any case, with both strategies there is no reason to call stat, just check the return of mkdir. llvm-svn: 201347
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp29
1 files changed, 18 insertions, 11 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 1e59c7adb5b..b21846c5483 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -751,20 +751,27 @@ error_code make_absolute(SmallVectorImpl<char> &path) {
"occurred above!");
}
-error_code create_directories(const Twine &path, bool &existed) {
- SmallString<128> path_storage;
- StringRef p = path.toStringRef(path_storage);
+error_code create_directories(const Twine &Path, bool &Existed) {
+ SmallString<128> PathStorage;
+ StringRef P = Path.toStringRef(PathStorage);
+
+ // Be optimistic and try to create the directory
+ error_code EC = create_directory(P, Existed);
+ // If we succeeded, or had any error other than the parent not existing, just
+ // return it.
+ if (EC != errc::no_such_file_or_directory)
+ return EC;
- StringRef parent = path::parent_path(p);
- if (!parent.empty()) {
- bool parent_exists;
- if (error_code ec = fs::exists(parent, parent_exists)) return ec;
+ // We failed because of a no_such_file_or_directory, try to create the
+ // parent.
+ StringRef Parent = path::parent_path(P);
+ if (Parent.empty())
+ return EC;
- if (!parent_exists)
- if (error_code ec = create_directories(parent, existed)) return ec;
- }
+ if ((EC = create_directories(Parent)))
+ return EC;
- return create_directory(p, existed);
+ return create_directory(P, Existed);
}
bool exists(file_status status) {
OpenPOWER on IntegriCloud