llvm.org GIT mirror llvm / d7c0273
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135167 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 8 years ago
2 changed file(s) with 4 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
139139 /// StringMapEntry object.
140140 const char *getKeyData() const {return reinterpret_cast(this+1);}
141141
142 const char *first() const { return getKeyData(); }
142 StringRef first() const { return StringRef(getKeyData(), getKeyLength()); }
143143
144144 /// Create - Create a StringMapEntry for the specified key and default
145145 /// construct the value.
5050
5151 // Iterator tests
5252 StringMap::iterator it = testMap.begin();
53 EXPECT_STREQ(testKey, it->first());
53 EXPECT_STREQ(testKey, it->first().data());
5454 EXPECT_EQ(testValue, it->second);
5555 ++it;
5656 EXPECT_TRUE(it == testMap.end());
156156 it != testMap.end(); ++it) {
157157 std::stringstream ss;
158158 ss << "key_" << it->second;
159 ASSERT_STREQ(ss.str().c_str(), it->first());
159 ASSERT_STREQ(ss.str().c_str(), it->first().data());
160160 visited[it->second] = true;
161161 }
162162
188188 StringMap::value_type* entry =
189189 StringMap::value_type::Create(
190190 testKeyFirst, testKeyFirst + testKeyLength, 1u);
191 EXPECT_STREQ(testKey, entry->first());
191 EXPECT_STREQ(testKey, entry->first().data());
192192 EXPECT_EQ(1u, entry->second);
193193 free(entry);
194194 }