diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-07-22 17:13:20 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-07-22 17:13:20 +0000 |
commit | dbe77cfa0bcae10d91fbdbf118a97ec212afc88e (patch) | |
tree | 9f6c4d9df8765d8bb66a7f98693bc66f8945b9a5 /include | |
parent | 59fec6a53234df91d6b66d5826ef1f8ce60af2fa (diff) |
Support writing a StringRef to a raw_ostream directly.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76754 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r-- | include/llvm/Support/raw_ostream.h | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/include/llvm/Support/raw_ostream.h b/include/llvm/Support/raw_ostream.h index 4c7338eac4..74a4206c23 100644 --- a/include/llvm/Support/raw_ostream.h +++ b/include/llvm/Support/raw_ostream.h @@ -15,6 +15,7 @@ #define LLVM_SUPPORT_RAW_OSTREAM_H #include "llvm/ADT/StringExtras.h" +#include "llvm/ADT/StringRef.h" #include <cassert> #include <cstring> #include <string> @@ -151,21 +152,27 @@ public: return *this; } - raw_ostream &operator<<(const char *Str) { - // Inline fast path, particulary for constant strings where a - // sufficiently smart compiler will simplify strlen. - - size_t Size = strlen(Str); + raw_ostream &operator<<(const StringRef &Str) { + // Inline fast path, particularly for strings with a known length. + size_t Size = Str.size(); // Make sure we can use the fast path. if (OutBufCur+Size > OutBufEnd) - return write(Str, Size); + return write(Str.data(), Size); - memcpy(OutBufCur, Str, Size); + memcpy(OutBufCur, Str.data(), Size); OutBufCur += Size; return *this; } + raw_ostream &operator<<(const char *Str) { + // Inline fast path, particulary for constant strings where a sufficiently + // smart compiler will simplify strlen. + + this->operator<<(StringRef(Str)); + return *this; + } + raw_ostream &operator<<(const std::string& Str) { write(Str.data(), Str.length()); return *this; |