Remove unused Target argument from AsmParser construction methods.
[oota-llvm.git] / include / llvm / ADT / SmallString.h
index fe97807d244d9d2ac13fc3373bbf05224e3a76e2..da264164821f2a9bcf209e4641dae75a6e8aa8da 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
-#include "llvm/Support/DataTypes.h"
-#include <cstring>
 
 namespace llvm {
 
@@ -29,6 +27,9 @@ public:
   // Default ctor - Initialize to empty.
   SmallString() {}
 
+  // Initialize from a StringRef.
+  SmallString(StringRef S) : SmallVector<char, InternalLen>(S.begin(), S.end()) {}
+
   // Initialize with a range.
   template<typename ItTy>
   SmallString(ItTy S, ItTy E) : SmallVector<char, InternalLen>(S, E) {}
@@ -38,24 +39,26 @@ public:
 
 
   // Extra methods.
-  const char *c_str() const {
-    SmallString *This = const_cast<SmallString*>(this);
-    // Ensure that there is a \0 at the end of the string.
-    This->reserve(this->size()+1);
-    This->End[0] = 0;
-    return this->begin();
+  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();
   }
 
-  StringRef str() const { return StringRef(this->begin(), this->size()); }
+  // Implicit conversion to StringRef.
+  operator StringRef() const { return str(); }
 
   // Extra operators.
-  const SmallString &operator=(const char *RHS) {
+  const SmallString &operator=(StringRef RHS) {
     this->clear();
     return *this += RHS;
   }
 
-  SmallString &operator+=(const char *RHS) {
-    this->append(RHS, RHS+strlen(RHS));
+  SmallString &operator+=(StringRef RHS) {
+    this->append(RHS.begin(), RHS.end());
     return *this;
   }
   SmallString &operator+=(char C) {
@@ -64,7 +67,6 @@ public:
   }
 };
 
-
 }
 
 #endif