Funny you should be making this change, as it is how I originally had the TypoEditDistanceMap. In r134009 last June, Doug changed TypoEditDistanceMap to "[d]ynamically allocate the StringMaps used in typo correction so that we don't rely on the existence of a copy constructor."<div>
<br></div><div>For the record, I prefer to not dynamically allocate the StringMaps so that manual deletion does not have to be done, making the code simpler to understand and reducing the potential for memory leaks. ;)</div>
<div><br></div><div>Cheers,</div><div>Kaelyn<br><br><div class="gmail_quote">On Sat, Apr 14, 2012 at 1:26 AM, Benjamin Kramer <span dir="ltr"><<a href="mailto:benny.kra@googlemail.com">benny.kra@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: d0k<br>
Date: Sat Apr 14 03:26:28 2012<br>
New Revision: 154736<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=154736&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=154736&view=rev</a><br>
Log:<br>
Directly store TypoResultsMaps in the TypoEditDistanceMap, getting rid of manual deletion.<br>
<br>
Modified:<br>
cfe/trunk/lib/Sema/SemaLookup.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaLookup.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=154736&r1=154735&r2=154736&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=154736&r1=154735&r2=154736&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Sat Apr 14 03:26:28 2012<br>
@@ -3165,7 +3165,7 @@<br>
namespace {<br>
<br>
typedef llvm::StringMap<TypoCorrection, llvm::BumpPtrAllocator> TypoResultsMap;<br>
-typedef std::map<unsigned, TypoResultsMap *> TypoEditDistanceMap;<br>
+typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;<br>
<br>
static const unsigned MaxTypoDistanceResultSets = 5;<br>
<br>
@@ -3187,14 +3187,6 @@<br>
: Typo(Typo->getName()),<br>
SemaRef(SemaRef) { }<br>
<br>
- ~TypoCorrectionConsumer() {<br>
- for (TypoEditDistanceMap::iterator I = BestResults.begin(),<br>
- IEnd = BestResults.end();<br>
- I != IEnd;<br>
- ++I)<br>
- delete I->second;<br>
- }<br>
-<br>
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, DeclContext *Ctx,<br>
bool InBaseClass);<br>
void FoundName(StringRef Name);<br>
@@ -3207,15 +3199,12 @@<br>
typedef TypoEditDistanceMap::iterator distance_iterator;<br>
distance_iterator begin() { return BestResults.begin(); }<br>
distance_iterator end() { return BestResults.end(); }<br>
- void erase(distance_iterator I) {<br>
- delete I->second;<br>
- BestResults.erase(I);<br>
- }<br>
+ void erase(distance_iterator I) { BestResults.erase(I); }<br>
unsigned size() const { return BestResults.size(); }<br>
bool empty() const { return BestResults.empty(); }<br>
<br>
TypoCorrection &operator[](StringRef Name) {<br>
- return (*BestResults.begin()->second)[Name];<br>
+ return BestResults.begin()->second[Name];<br>
}<br>
<br>
unsigned getBestEditDistance(bool Normalized) {<br>
@@ -3279,11 +3268,9 @@<br>
<br>
void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) {<br>
StringRef Name = Correction.getCorrectionAsIdentifierInfo()->getName();<br>
- TypoResultsMap *& Map = BestResults[Correction.getEditDistance(false)];<br>
- if (!Map)<br>
- Map = new TypoResultsMap;<br>
+ TypoResultsMap &Map = BestResults[Correction.getEditDistance(false)];<br>
<br>
- TypoCorrection &CurrentCorrection = (*Map)[Name];<br>
+ TypoCorrection &CurrentCorrection = Map[Name];<br>
if (!CurrentCorrection ||<br>
// FIXME: The following should be rolled up into an operator< on<br>
// TypoCorrection with a more principled definition.<br>
@@ -3881,8 +3868,8 @@<br>
while (!Consumer.empty()) {<br>
TypoCorrectionConsumer::distance_iterator DI = Consumer.begin();<br>
unsigned ED = DI->first;<br>
- for (TypoCorrectionConsumer::result_iterator I = DI->second->begin(),<br>
- IEnd = DI->second->end();<br>
+ for (TypoCorrectionConsumer::result_iterator I = DI->second.begin(),<br>
+ IEnd = DI->second.end();<br>
I != IEnd; /* Increment in loop. */) {<br>
// If the item already has been looked up or is a keyword, keep it.<br>
// If a validator callback object was given, drop the correction<br>
@@ -3891,7 +3878,7 @@<br>
TypoCorrectionConsumer::result_iterator Prev = I;<br>
++I;<br>
if (!isCandidateViable(CCC, Prev->second))<br>
- DI->second->erase(Prev);<br>
+ DI->second.erase(Prev);<br>
continue;<br>
}<br>
<br>
@@ -3910,7 +3897,7 @@<br>
{<br>
TypoCorrectionConsumer::result_iterator Next = I;<br>
++Next;<br>
- DI->second->erase(I);<br>
+ DI->second.erase(I);<br>
I = Next;<br>
}<br>
break;<br>
@@ -3928,7 +3915,7 @@<br>
I->second.addCorrectionDecl(*TRD);<br>
++I;<br>
if (!isCandidateViable(CCC, Prev->second))<br>
- DI->second->erase(Prev);<br>
+ DI->second.erase(Prev);<br>
break;<br>
}<br>
<br>
@@ -3937,14 +3924,14 @@<br>
I->second.setCorrectionDecl(TmpRes.getAsSingle<NamedDecl>());<br>
++I;<br>
if (!isCandidateViable(CCC, Prev->second))<br>
- DI->second->erase(Prev);<br>
+ DI->second.erase(Prev);<br>
break;<br>
}<br>
<br>
}<br>
}<br>
<br>
- if (DI->second->empty())<br>
+ if (DI->second.empty())<br>
Consumer.erase(DI);<br>
else if (!getLangOpts().CPlusPlus || QualifiedResults.empty() || !ED)<br>
// If there are results in the closest possible bucket, stop<br>
@@ -4008,7 +3995,7 @@<br>
// No corrections remain...<br>
if (Consumer.empty()) return TypoCorrection();<br>
<br>
- TypoResultsMap &BestResults = *Consumer.begin()->second;<br>
+ TypoResultsMap &BestResults = Consumer.begin()->second;<br>
ED = TypoCorrection::NormalizeEditDistance(Consumer.begin()->first);<br>
<br>
if (ED > 0 && Typo->getName().size() / ED < 3) {<br>
@@ -4082,7 +4069,8 @@<br>
std::string tmpBuffer;<br>
llvm::raw_string_ostream PrefixOStream(tmpBuffer);<br>
CorrectionNameSpec->print(PrefixOStream, PrintingPolicy(LO));<br>
- return PrefixOStream.str() + CorrectionName.getAsString();<br>
+ CorrectionName.printName(PrefixOStream);<br>
+ return PrefixOStream.str();<br>
}<br>
<br>
return CorrectionName.getAsString();<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>