]> sourceware.org Git - systemtap.git/commitdiff
string_ref: correct interned_string substr / c_str conflict
authorFrank Ch. Eigler <fche@redhat.com>
Wed, 19 Aug 2015 18:21:41 +0000 (14:21 -0400)
committerFrank Ch. Eigler <fche@redhat.com>
Wed, 19 Aug 2015 18:21:41 +0000 (14:21 -0400)
jistone pointed out a possible problem in the interned_string
implementation; we break the tie in favour of trivial c_str()
(since commit 3e4547ad096d showed its value).

stringtable.cxx
stringtable.h

index 384925d679c66c29128d0221905c5e9ae3c22317..e5c2491b1341aace0293d11d5119d372b3025b9d 100644 (file)
@@ -91,6 +91,7 @@ stringtable_t stringtable;
 // because std::set<> guarantees iterator validity across inserts,
 // which means that our value strings stay put.
 
+// static
 interned_string interned_string::intern(const string& value)
 {
   stringtable_t::iterator it = (stringtable.insert(value)).first; // persistent iterator!
index 72cdd4d354c944b3ee869c6d6208248538dc74c9..4455c9be83160e97ef097cf716a30eb5da1a484c 100644 (file)
@@ -38,12 +38,19 @@ struct interned_string: public boost::string_ref
   // NB: this is OK because we always use a std::string as a backing
   // store, and as of c++0x, those always store a \0 in their data().
   const char* c_str() const { return this->size() ? (const char*)this->data() : ""; }
+  // NB: the above property holds only if we don't expose the efficient
+  // boost::string_ref substrings.  We can either have efficient
+  // substrings -xor- implicit \0 terminators - not both.
+  interned_string substr(size_t pos = 0, size_t len = npos) const
+  {
+    return interned_string::intern (boost::string_ref::substr(pos, len).to_string());
+  }
 
   // boost oversights
   template <typename F>
   size_t find (const F& f, size_t start_pos)
   {
-    size_t x = this->substr(start_pos).find(f);
+    size_t x = this->boost::string_ref::substr(start_pos).find(f); // don't intern substring unnecessarily
     if (x == boost::string_ref::npos)
       return x;
     else
@@ -63,7 +70,7 @@ struct interned_string: public boost::string_ref
 #endif
   
 private:
-  interned_string intern(const std::string& value);
+  static interned_string intern(const std::string& value);
 };
 #else /* !defined(HAVE_BOOST_UTILITY_STRING_REF_HPP) */
 
This page took 0.029949 seconds and 5 git commands to generate.