namespace {
typedef llvm::StringMap<TypoCorrection, llvm::BumpPtrAllocator> TypoResultsMap;
-typedef std::map<unsigned, TypoResultsMap> TypoEditDistanceMap;
+typedef std::map<unsigned, TypoResultsMap *> TypoEditDistanceMap;
static const unsigned MaxTypoDistanceResultSets = 5;
MaxEditDistance((std::numeric_limits<unsigned>::max)()),
SemaRef(SemaRef) { }
+ ~TypoCorrectionConsumer() {
+ for (TypoEditDistanceMap::iterator I = BestResults.begin(),
+ IEnd = BestResults.end();
+ I != IEnd;
+ ++I)
+ delete I->second;
+ }
+
virtual void FoundDecl(NamedDecl *ND, NamedDecl *Hiding, bool InBaseClass);
void FoundName(llvm::StringRef Name);
void addKeywordResult(llvm::StringRef Keyword);
bool empty() const { return BestResults.empty(); }
TypoCorrection &operator[](llvm::StringRef Name) {
- return BestResults.begin()->second[Name];
+ return (*BestResults.begin()->second)[Name];
}
unsigned getMaxEditDistance() const {
void TypoCorrectionConsumer::addCorrection(TypoCorrection Correction) {
llvm::StringRef Name = Correction.getCorrectionAsIdentifierInfo()->getName();
- BestResults[Correction.getEditDistance()][Name] = Correction;
+ TypoResultsMap *& Map = BestResults[Correction.getEditDistance()];
+ if (!Map)
+ Map = new TypoResultsMap;
+ (*Map)[Name] = Correction;
while (BestResults.size() > MaxTypoDistanceResultSets) {
- BestResults.erase(--BestResults.end());
+ TypoEditDistanceMap::iterator Last = BestResults.end();
+ --Last;
+ delete Last->second;
+ BestResults.erase(Last);
}
}
while (!Consumer.empty()) {
TypoCorrectionConsumer::distance_iterator DI = Consumer.begin();
unsigned ED = DI->first;
- for (TypoCorrectionConsumer::result_iterator I = DI->second.begin(),
- IEnd = DI->second.end();
+ for (TypoCorrectionConsumer::result_iterator I = DI->second->begin(),
+ IEnd = DI->second->end();
I != IEnd; /* Increment in loop. */) {
// If the item already has been looked up or is a keyword, keep it
if (I->second.isResolved()) {
{
TypoCorrectionConsumer::result_iterator Next = I;
++Next;
- DI->second.erase(I);
+ DI->second->erase(I);
I = Next;
}
break;
}
}
- if (DI->second.empty())
+ if (DI->second->empty())
Consumer.erase(DI);
else if (!getLangOptions().CPlusPlus || QualifiedResults.empty() || !ED)
// If there are results in the closest possible bucket, stop
// No corrections remain...
if (Consumer.empty()) return TypoCorrection();
- TypoResultsMap &BestResults = Consumer.begin()->second;
+ TypoResultsMap &BestResults = *Consumer.begin()->second;
ED = Consumer.begin()->first;
if (ED > 0 && Typo->getName().size() / ED < 3) {
// corrections without additional namespace qualifiers)
if (getLangOptions().CPlusPlus && BestResults.size() > 1) {
TypoCorrectionConsumer::distance_iterator DI = Consumer.begin();
- for (TypoCorrectionConsumer::result_iterator I = DI->second.begin(),
- IEnd = DI->second.end();
+ for (TypoCorrectionConsumer::result_iterator I = DI->second->begin(),
+ IEnd = DI->second->end();
I != IEnd; /* Increment in loop. */) {
if (I->second.getCorrectionSpecifier() != NULL) {
TypoCorrectionConsumer::result_iterator Cur = I;
++I;
- DI->second.erase(Cur);
+ DI->second->erase(Cur);
} else ++I;
}
}