Optimization, improved Match(). The str[0] == '%' improvement

This commit is contained in:
Reijo Tomperi 2008-12-23 20:17:05 +00:00
parent b32663324e
commit c4ecdf06f0
1 changed files with 73 additions and 49 deletions

View File

@ -182,17 +182,25 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
return true; return true;
bool useVar1; bool useVar1;
// Compare the first character of the string for optimization reasons
// before doing more detailed checks.
bool patternIdentified = false;
if( str[0] == '%' )
{
// Any symbolname.. // Any symbolname..
if (strcmp(str,"%var%")==0 || strcmp(str,"%type%")==0) if (strcmp(str,"%var%")==0 || strcmp(str,"%type%")==0)
{ {
if (!tok->isName()) if (!tok->isName())
return false; return false;
patternIdentified = true;
} }
// Accept any token // Accept any token
else if (strcmp(str,"%any%")==0 ) else if (strcmp(str,"%any%")==0 )
{ {
patternIdentified = true;
} }
// Variable name.. // Variable name..
@ -219,30 +227,46 @@ bool TOKEN::Match(const TOKEN *tok, const char pattern[], const char *varname1[]
tok = tok->tokAt(2); tok = tok->tokAt(2);
} }
patternIdentified = true;
} }
else if (strcmp(str,"%varid%")==0) else if (strcmp(str,"%varid%")==0)
{ {
if ( tok->varId() != varid ) if ( tok->varId() != varid )
return false; return false;
patternIdentified = true;
} }
else if (strcmp(str,"%num%")==0) else if (strcmp(str,"%num%")==0)
{ {
if ( !tok->isNumber() ) if ( !tok->isNumber() )
return false; return false;
patternIdentified = true;
} }
else if (strcmp(str,"%bool%")==0) else if (strcmp(str,"%bool%")==0)
{ {
if ( !tok->isBoolean() ) if ( !tok->isBoolean() )
return false; return false;
patternIdentified = true;
} }
else if (strcmp(str,"%str%")==0) else if (strcmp(str,"%str%")==0)
{ {
if ( tok->_str[0] != '\"' ) if ( tok->_str[0] != '\"' )
return false; return false;
patternIdentified = true;
}
}
if( patternIdentified )
{
// Pattern was identified already above.
} }
// [.. => search for a one-character token.. // [.. => search for a one-character token..