]> granicus.if.org Git - clang/commitdiff
Delete the TypoResultsMap when erasing the pointer to it.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Apr 2012 23:09:10 +0000 (23:09 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 13 Apr 2012 23:09:10 +0000 (23:09 +0000)
This manual deleting is error-prone, but we can't just put an OwningPtr in a
std::map :(

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

lib/Sema/SemaLookup.cpp

index 966eb90306a9977193bc28a4ff0f85889e783ae6..06697b6a68ed4c87c910301b59f0c339ce568534 100644 (file)
@@ -3207,7 +3207,10 @@ public:
   typedef TypoEditDistanceMap::iterator distance_iterator;
   distance_iterator begin() { return BestResults.begin(); }
   distance_iterator end()  { return BestResults.end(); }
-  void erase(distance_iterator I) { BestResults.erase(I); }
+  void erase(distance_iterator I) {
+    delete I->second;
+    BestResults.erase(I);
+  }
   unsigned size() const { return BestResults.size(); }
   bool empty() const { return BestResults.empty(); }
 
@@ -3289,12 +3292,8 @@ void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) {
       CurrentCorrection.getAsString(SemaRef.getLangOpts()))
     CurrentCorrection = Correction;
 
-  while (BestResults.size() > MaxTypoDistanceResultSets) {
-    TypoEditDistanceMap::iterator Last = BestResults.end();
-    --Last;
-    delete Last->second;
-    BestResults.erase(Last);
-  }
+  while (BestResults.size() > MaxTypoDistanceResultSets)
+    erase(llvm::prior(BestResults.end()));
 }
 
 // Fill the supplied vector with the IdentifierInfo pointers for each piece of