Make StringSet::insert return pair<iterator, bool> like other self-associative containers
authorDavid Blaikie <dblaikie@gmail.com>
Wed, 19 Nov 2014 02:56:00 +0000 (02:56 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Wed, 19 Nov 2014 02:56:00 +0000 (02:56 +0000)
StringSet is still a bit dodgy in that it exposes the raw iterator of
the StringMap parent, which exposes the weird detail that StringSet
actually has a 'value'... but anyway, this is useful for a handful of
clients that want to reference the newly inserted/persistent string data
in the StringSet/Map/Entry/thing.

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

include/llvm/ADT/StringSet.h
tools/opt/BreakpointPrinter.cpp
utils/FileCheck/FileCheck.cpp
utils/TableGen/DAGISelMatcherOpt.cpp

index 7bea577f34d33f411f592d15b8be050d119d4441..3e0cc200b6dda62125010288f5e0c264f697460d 100644 (file)
@@ -24,20 +24,9 @@ namespace llvm {
     typedef llvm::StringMap<char, AllocatorTy> base;
   public:
 
-    /// insert - Insert the specified key into the set.  If the key already
-    /// exists in the set, return false and ignore the request, otherwise insert
-    /// it and return true.
-    bool insert(StringRef Key) {
-      // Get or create the map entry for the key; if it doesn't exist the value
-      // type will be default constructed which we use to detect insert.
-      //
-      // We use '+' as the sentinel value in the map.
+    std::pair<typename base::iterator, bool> insert(StringRef Key) {
       assert(!Key.empty());
-      StringMapEntry<char> &Entry = this->GetOrCreateValue(Key);
-      if (Entry.getValue() == '+')
-        return false;
-      Entry.setValue('+');
-      return true;
+      return base::insert(std::make_pair(Key, '\0'));
     }
   };
 }
index 44f4a11773ef43bad82520c13919ac107bd7854e..3cbc0ae50f14db8571f46bb1dd6b3e7bdac4e72d 100644 (file)
@@ -62,7 +62,7 @@ struct BreakpointPrinter : public ModulePass {
           continue;
         getContextName(SP.getContext().resolve(TypeIdentifierMap), Name);
         Name = Name + SP.getDisplayName().str();
-        if (!Name.empty() && Processed.insert(Name)) {
+        if (!Name.empty() && Processed.insert(Name).second) {
           Out << Name << "\n";
         }
       }
index 9606e64d6f8937482b60a18650e74a6f885ac5b6..59affa1ada1ba2b2c61d25d1593fa5f44404d1e6 100644 (file)
@@ -1219,7 +1219,7 @@ static bool ValidateCheckPrefixes() {
     if (Prefix == "")
       return false;
 
-    if (!PrefixSet.insert(Prefix))
+    if (!PrefixSet.insert(Prefix).second)
       return false;
 
     if (!ValidateCheckPrefix(Prefix))
index 0c18e0b1c29add3b4833b8dd52f73bbdd4a66d46..7a22764ec35d995c18833f39d9c8bf493838f4a9 100644 (file)
@@ -454,7 +454,7 @@ static void FactorNodes(std::unique_ptr<Matcher> &MatcherPtr) {
     SmallVector<std::pair<const SDNodeInfo*, Matcher*>, 8> Cases;
     for (unsigned i = 0, e = NewOptionsToMatch.size(); i != e; ++i) {
       CheckOpcodeMatcher *COM = cast<CheckOpcodeMatcher>(NewOptionsToMatch[i]);
-      assert(Opcodes.insert(COM->getOpcode().getEnumName()) &&
+      assert(Opcodes.insert(COM->getOpcode().getEnumName()).second &&
              "Duplicate opcodes not factored?");
       Cases.push_back(std::make_pair(&COM->getOpcode(), COM->getNext()));
     }