Opimization: Remove combineWithNext Member, use an array instead
This commit is contained in:
parent
56c1a91e67
commit
1f141e4dc0
12
token.cpp
12
token.cpp
|
@ -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;
|
||||
|
|
7
token.h
7
token.h
|
@ -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.
|
||||
*/
|
||||
|
|
55
tokenize.cpp
55
tokenize.cpp
|
@ -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(".");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue