The key of a StringMap can contain nul's in it, so having first() return
authorChris Lattner <sabre@nondot.org>
Thu, 14 Jul 2011 18:31:43 +0000 (18:31 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 14 Jul 2011 18:31:43 +0000 (18:31 +0000)
const char* doesn't make sense.  Have it return StringRef instead.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135167 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/StringMap.h
unittests/ADT/StringMapTest.cpp

index 95c973bcc9a13b48a91ab847cccdb470f752f302..35077879351bdf2aeb455adc771bd00b7f2eb4ab 100644 (file)
@@ -140,7 +140,7 @@ public:
   /// 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.
index ea91348a5bdf730e92085d5778ad1c78b6de18bc..2ae58204e183ac57dcdedb259139a4bd33f05cd4 100644 (file)
@@ -51,7 +51,7 @@ protected:
 
     // 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 @@ TEST_F(StringMapTest, IterationTest) {
       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 @@ TEST_F(StringMapTest, StringMapEntryTest) {
   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);
 }