From 58fe86dc0ecb7efff01abe2b0024a6a53ebb2c81 Mon Sep 17 00:00:00 2001 From: "Michael J. Spencer" Date: Thu, 9 Dec 2010 17:37:18 +0000 Subject: [PATCH] Support: Move c_str from SmallVector back to SmallString and add a free standing templated c_str in Windows.h to replace it. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121381 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/SmallString.h | 7 +++++++ include/llvm/ADT/SmallVector.h | 7 ------- lib/Support/Windows/PathV2.inc | 2 +- lib/Support/Windows/Windows.h | 13 +++++++++++++ 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/llvm/ADT/SmallString.h b/include/llvm/ADT/SmallString.h index 73285608221..4388a85edbe 100644 --- a/include/llvm/ADT/SmallString.h +++ b/include/llvm/ADT/SmallString.h @@ -38,6 +38,13 @@ public: // Extra methods. StringRef str() const { return StringRef(this->begin(), this->size()); } + // TODO: Make this const, if it's safe... + const char* c_str() { + this->push_back(0); + this->pop_back(); + return this->data(); + } + // Implicit conversion to StringRef. operator StringRef() const { return str(); } diff --git a/include/llvm/ADT/SmallVector.h b/include/llvm/ADT/SmallVector.h index 123b85daff8..1c86622ad83 100644 --- a/include/llvm/ADT/SmallVector.h +++ b/include/llvm/ADT/SmallVector.h @@ -340,13 +340,6 @@ public: return Result; } - // TODO: Make this const, if it's safe... - typename SuperClass::const_pointer c_str() { - push_back(0); - pop_back(); - return this->data(); - } - void swap(SmallVectorImpl &RHS); /// append - Add the specified range to the end of the SmallVector. diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc index 6a1ea939141..6b425c41d5e 100644 --- a/lib/Support/Windows/PathV2.inc +++ b/lib/Support/Windows/PathV2.inc @@ -623,7 +623,7 @@ error_code directory_iterator_construct(directory_iterator& it, // Get the first directory entry. WIN32_FIND_DATAW FirstFind; - ScopedFindHandle FindHandle(::FindFirstFileW(path_utf16.c_str(), &FirstFind)); + ScopedFindHandle FindHandle(::FindFirstFileW(c_str(path_utf16), &FirstFind)); if (!FindHandle) return windows_error(::GetLastError()); diff --git a/lib/Support/Windows/Windows.h b/lib/Support/Windows/Windows.h index 12ddc92e7ca..6e0b585b975 100644 --- a/lib/Support/Windows/Windows.h +++ b/lib/Support/Windows/Windows.h @@ -102,3 +102,16 @@ public: typedef ScopedHandle ScopedFindHandle; + +namespace llvm { +template +class SmallVectorImpl; + +template +typename SmallVectorImpl::const_pointer +c_str(SmallVectorImpl &str) { + str.push_back(0); + str.pop_back(); + return str.data(); +} +} // end namespace llvm. -- 2.34.1