Opimization: Remove combineWithNext Member, use an array instead

This commit is contained in:
Nicolas Le Cam 2008-12-21 17:35:33 +00:00
parent 56c1a91e67
commit 1f141e4dc0
3 changed files with 34 additions and 50 deletions

View File

@ -64,18 +64,6 @@ void TOKEN::setstr( const char s[] )
_varId = 0;
}
void TOKEN::combineWithNext(const char str1[], const char str2[])
{
if (!(_next))
return;
if (_str!=str1 || _next->_str!=str2)
return;
std::string newstr(std::string(str1) + std::string(str2));
setstr( newstr.c_str() );
deleteNext();
}
void TOKEN::deleteNext()
{
TOKEN *n = _next;

View File

@ -40,13 +40,6 @@ public:
char aaaa1() const
{ return _cstr[1]; }
/**
* Combine two tokens that belong to each other.
* Ex: "<" and "=" may become "<="
*/
void combineWithNext(const char str1[], const char str2[]);
/**
* Unlink and delete next token.
*/

View File

@ -499,38 +499,41 @@ void Tokenizer::tokenizeCode(std::istream &code, const unsigned int FileIndex)
// Combine tokens..
for (TOKEN *tok = _tokens; tok && tok->next(); tok = tok->next())
{
tok->combineWithNext("<", "<");
tok->combineWithNext(">", ">");
static const char* combineWithNext[][3] =
{
{ "<", "<", "<<" },
{ ">", ">", ">>" },
tok->combineWithNext("&", "&");
tok->combineWithNext("|", "|");
{ "&", "&", "&&" },
{ "|", "|", "||" },
tok->combineWithNext("+", "=");
tok->combineWithNext("-", "=");
tok->combineWithNext("*", "=");
tok->combineWithNext("/", "=");
tok->combineWithNext("&", "=");
tok->combineWithNext("|", "=");
{ "+", "=", "+=" },
{ "-", "=", "-=" },
{ "*", "=", "*=" },
{ "/", "=", "/=" },
{ "&", "=", "&=" },
{ "|", "=", "|=" },
tok->combineWithNext("=", "=");
tok->combineWithNext("!", "=");
tok->combineWithNext("<", "=");
tok->combineWithNext(">", "=");
{ "=", "=", "==" },
{ "!", "=", "!=" },
{ "<", "=", "<=" },
{ ">", "=", ">=" },
tok->combineWithNext(":", ":");
tok->combineWithNext("-", ">");
{ ":", ":", "::" },
{ "-", ">", "." }, // Replace "->" with "."
tok->combineWithNext("private", ":");
tok->combineWithNext("protected", ":");
tok->combineWithNext("public", ":");
{ "private", ":", "private:" },
{ "protected", ":", "protected:" },
{ "public", ":", "public:" }
};
for (int i = 0; i < sizeof(combineWithNext) / sizeof(combineWithNext[0]); i++)
{
if ( tok->str() == combineWithNext[i][0] && tok->next()->str() == combineWithNext[i][1] )
{
tok->setstr(combineWithNext[i][2]);
tok->deleteNext();
}
// Replace "->" with "."
for ( TOKEN *tok = _tokens; tok; tok = tok->next() )
{
if ( tok->str() == "->" )
{
tok->setstr(".");
}
}