[llvm-commits] [llvm] r135167 - in /llvm/trunk: include/llvm/ADT/StringMap.h unittests/ADT/StringMapTest.cpp

Chris Lattner sabre at nondot.org
Thu Jul 14 11:31:43 PDT 2011


Author: lattner
Date: Thu Jul 14 13:31:43 2011
New Revision: 135167

URL: http://llvm.org/viewvc/llvm-project?rev=135167&view=rev
Log:
The key of a StringMap can contain nul's in it, so having first() return
const char* doesn't make sense.  Have it return StringRef instead.

Modified:
    llvm/trunk/include/llvm/ADT/StringMap.h
    llvm/trunk/unittests/ADT/StringMapTest.cpp

Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=135167&r1=135166&r2=135167&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Thu Jul 14 13:31:43 2011
@@ -140,7 +140,7 @@
   /// StringMapEntry object.
   const char *getKeyData() const {return reinterpret_cast<const char*>(this+1);}
 
-  const char *first() const { return getKeyData(); }
+  StringRef first() const { return StringRef(getKeyData(), getKeyLength()); }
 
   /// Create - Create a StringMapEntry for the specified key and default
   /// construct the value.

Modified: llvm/trunk/unittests/ADT/StringMapTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ADT/StringMapTest.cpp?rev=135167&r1=135166&r2=135167&view=diff
==============================================================================
--- llvm/trunk/unittests/ADT/StringMapTest.cpp (original)
+++ llvm/trunk/unittests/ADT/StringMapTest.cpp Thu Jul 14 13:31:43 2011
@@ -51,7 +51,7 @@
 
     // Iterator tests
     StringMap<uint32_t>::iterator it = testMap.begin();
-    EXPECT_STREQ(testKey, it->first());
+    EXPECT_STREQ(testKey, it->first().data());
     EXPECT_EQ(testValue, it->second);
     ++it;
     EXPECT_TRUE(it == testMap.end());
@@ -157,7 +157,7 @@
       it != testMap.end(); ++it) {
     std::stringstream ss;
     ss << "key_" << it->second;
-    ASSERT_STREQ(ss.str().c_str(), it->first());
+    ASSERT_STREQ(ss.str().c_str(), it->first().data());
     visited[it->second] = true;
   }
 
@@ -189,7 +189,7 @@
   StringMap<uint32_t>::value_type* entry =
       StringMap<uint32_t>::value_type::Create(
           testKeyFirst, testKeyFirst + testKeyLength, 1u);
-  EXPECT_STREQ(testKey, entry->first());
+  EXPECT_STREQ(testKey, entry->first().data());
   EXPECT_EQ(1u, entry->second);
   free(entry);
 }





More information about the llvm-commits mailing list