FBString conservative additions
authorNicholas Ormrod <njormrod@fb.com>
Sat, 14 Jun 2014 01:09:44 +0000 (18:09 -0700)
committerAnton Likhtarov <alikhtarov@fb.com>
Thu, 26 Jun 2014 02:24:01 +0000 (19:24 -0700)
Summary:
Now that fbstring is conservative by default (D1373308), we can remove
the mutability of the data members and the call to c_str() in operator[].

Test Plan: fbconfig -r folly && fbmake runtests

Reviewed By: lucian@fb.com

Subscribers: folly@lists, sdwilsh, njormrod

FB internal diff: D1382644

folly/FBString.h

index 147235341ff843ecbd5c5662c1e32eda3a1c9f4b..2f4c9a445a3fa7d4c41afd01e7fc936173c79036 100644 (file)
@@ -797,8 +797,8 @@ private:
   };
 
   union {
-    mutable Char small_[sizeof(MediumLarge) / sizeof(Char)];
-    mutable MediumLarge ml_;
+    Char small_[sizeof(MediumLarge) / sizeof(Char)];
+    MediumLarge ml_;
   };
 
   enum {
@@ -1247,14 +1247,10 @@ public:
 
   // C++11 21.4.5 element access:
   const_reference operator[](size_type pos) const {
-    return *(c_str() + pos);
+    return *(begin() + pos);
   }
 
   reference operator[](size_type pos) {
-    if (pos == size()) {
-      // Just call c_str() to make sure '\0' is present
-      c_str();
-    }
     return *(begin() + pos);
   }