Use a map for the memoization.

This commit is contained in:
Roberto Raggi
2009-11-16 18:00:20 +01:00
parent 881f62e965
commit 0b641d38d5
2 changed files with 11 additions and 8 deletions

View File

@@ -441,6 +441,8 @@ bool Parser::parseTranslationUnit(TranslationUnitAST *&node)
rewind(start_declaration + 1); rewind(start_declaration + 1);
skipUntilDeclaration(); skipUntilDeclaration();
} }
_templateArgumentList.clear();
} }
node = ast; node = ast;
@@ -568,6 +570,8 @@ bool Parser::parseLinkageBody(DeclarationAST *&node)
rewind(start_declaration + 1); rewind(start_declaration + 1);
skipUntilDeclaration(); skipUntilDeclaration();
} }
_templateArgumentList.clear();
} }
match(T_RBRACE, &ast->rbrace_token); match(T_RBRACE, &ast->rbrace_token);
node = ast; node = ast;
@@ -692,11 +696,9 @@ bool Parser::parseOperatorFunctionId(NameAST *&node)
Parser::TemplateArgumentListEntry *Parser::templateArgumentListEntry(unsigned tokenIndex) Parser::TemplateArgumentListEntry *Parser::templateArgumentListEntry(unsigned tokenIndex)
{ {
for (unsigned i = 0; i < _templateArgumentList.size(); ++i) { std::map<unsigned, TemplateArgumentListEntry>::iterator it =_templateArgumentList.find(tokenIndex);
TemplateArgumentListEntry *entry = &_templateArgumentList[i]; if (it != _templateArgumentList.end())
if (entry->index == tokenIndex) return &it->second;
return entry;
}
return 0; return 0;
} }
@@ -729,11 +731,11 @@ bool Parser::parseTemplateArgumentList(TemplateArgumentListAST *&node)
} }
} }
_templateArgumentList.push_back(TemplateArgumentListEntry(start, cursor(), node)); _templateArgumentList.insert(std::make_pair(cursor(), TemplateArgumentListEntry(start, cursor(), node)));
return true; return true;
} }
_templateArgumentList.push_back(TemplateArgumentListEntry(start, cursor(), 0)); _templateArgumentList.insert(std::make_pair(cursor(), TemplateArgumentListEntry(start, cursor(), 0)));
return false; return false;
} }

View File

@@ -53,6 +53,7 @@
#include "ASTfwd.h" #include "ASTfwd.h"
#include "Token.h" #include "Token.h"
#include "TranslationUnit.h" #include "TranslationUnit.h"
#include <map>
namespace CPlusPlus { namespace CPlusPlus {
@@ -308,7 +309,7 @@ private:
bool _inFunctionBody: 1; bool _inFunctionBody: 1;
bool _inObjCImplementationContext: 1; bool _inObjCImplementationContext: 1;
Array<TemplateArgumentListEntry> _templateArgumentList; std::map<unsigned, TemplateArgumentListEntry> _templateArgumentList;
class Rewind; class Rewind;
friend class Rewind; friend class Rewind;