diff options
author | Yaron Keren <yaron.keren@gmail.com> | 2015-07-23 05:49:29 +0000 |
---|---|---|
committer | Yaron Keren <yaron.keren@gmail.com> | 2015-07-23 05:49:29 +0000 |
commit | 4135e4c47528885b7b8967c009cf356a1c0c6b1f (patch) | |
tree | a2bf0e657827a0887fcbb42dd99c74b1fa472a9d /llvm/lib/Support/Unix/Signals.inc | |
parent | 6a3fdeca224e284ef4c43b88ff3478e6cb404d3a (diff) | |
download | llvm-4135e4c47528885b7b8967c009cf356a1c0c6b1f.zip llvm-4135e4c47528885b7b8967c009cf356a1c0c6b1f.tar.gz llvm-4135e4c47528885b7b8967c009cf356a1c0c6b1f.tar.bz2 |
Remove unnecessary in C++11 c_str() calls
While theoratically required in pre-C++11 to avoid re-allocation upon call,
C++11 guarantees that c_str() returns a pointer to the internal array so
pre-calling c_str() is no longer required.
llvm-svn: 242983
Diffstat (limited to 'llvm/lib/Support/Unix/Signals.inc')
-rw-r--r-- | llvm/lib/Support/Unix/Signals.inc | 19 |
1 files changed, 1 insertions, 18 deletions
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc index 2332db5..9433630 100644 --- a/llvm/lib/Support/Unix/Signals.inc +++ b/llvm/lib/Support/Unix/Signals.inc @@ -144,9 +144,6 @@ static void RemoveFilesToRemove() { // memory. std::vector<std::string>& FilesToRemoveRef = *FilesToRemove; for (unsigned i = 0, e = FilesToRemoveRef.size(); i != e; ++i) { - // We rely on a std::string implementation for which repeated calls to - // 'c_str()' don't allocate memory. We pre-call 'c_str()' on all of these - // strings to try to ensure this is safe. const char *path = FilesToRemoveRef[i].c_str(); // Get the status so we can determine if it's a file or directory. If we @@ -231,21 +228,7 @@ bool llvm::sys::RemoveFileOnSignal(StringRef Filename, std::string* ErrMsg) { { sys::SmartScopedLock<true> Guard(*SignalsMutex); - std::vector<std::string>& FilesToRemoveRef = *FilesToRemove; - std::string *OldPtr = - FilesToRemoveRef.empty() ? nullptr : &FilesToRemoveRef[0]; - FilesToRemoveRef.push_back(Filename); - - // We want to call 'c_str()' on every std::string in this vector so that if - // the underlying implementation requires a re-allocation, it happens here - // rather than inside of the signal handler. If we see the vector grow, we - // have to call it on every entry. If it remains in place, we only need to - // call it on the latest one. - if (OldPtr == &FilesToRemoveRef[0]) - FilesToRemoveRef.back().c_str(); - else - for (unsigned i = 0, e = FilesToRemoveRef.size(); i != e; ++i) - FilesToRemoveRef[i].c_str(); + FilesToRemove->push_back(Filename); } RegisterHandlers(); |