Skip to content

Commit ce43679

Browse files
author
git apple-llvm automerger
committed
Merge commit '6952b7e09497' from apple/master into swift/master-next
2 parents 814f051 + 6952b7e commit ce43679

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

llvm/include/llvm/ADT/StringSet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class StringSet : public StringMap<NoneType, AllocatorTy> {
4545
insert(const StringMapEntry<ValueTy> &mapEntry) {
4646
return insert(mapEntry.getKey());
4747
}
48+
49+
/// Check if the set contains the given \c key.
50+
bool contains(StringRef key) const { return Base::FindKey(key) != -1; }
4851
};
4952

5053
} // end namespace llvm

llvm/unittests/ADT/StringSetTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,23 @@ TEST_F(StringSetTest, EmptyString) {
5353
EXPECT_EQ(Count, 1UL);
5454
}
5555

56+
TEST_F(StringSetTest, Contains) {
57+
StringSet<> Set;
58+
EXPECT_FALSE(Set.contains(""));
59+
EXPECT_FALSE(Set.contains("test"));
60+
61+
Set.insert("");
62+
Set.insert("test");
63+
EXPECT_TRUE(Set.contains(""));
64+
EXPECT_TRUE(Set.contains("test"));
65+
66+
Set.insert("test");
67+
EXPECT_TRUE(Set.contains(""));
68+
EXPECT_TRUE(Set.contains("test"));
69+
70+
Set.erase("test");
71+
EXPECT_TRUE(Set.contains(""));
72+
EXPECT_FALSE(Set.contains("test"));
73+
}
74+
5675
} // end anonymous namespace

0 commit comments

Comments
 (0)