Ignore:
Timestamp:
Jul 10, 2010, 5:11:08 PM (15 years ago)
Author:
[email protected]
Message:

2010-07-10 Oliver Hunt <[email protected]>

Reviewed by Gavin Barraclough.

Remove switches from inner expression loops in the parser
https://bugs.webkit.org/show_bug.cgi?id=42035

Use bitmasks and flags on the token types to identify unary and
binary operators, rather than switching on the token type to
identify them.

  • parser/JSParser.cpp: (JSC::isUnaryOp): (JSC::JSParser::isBinaryOperator):
  • parser/JSParser.h: (JSC::):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/parser/JSParser.cpp

    r63024 r63055  
    5959#define TreeProperty typename TreeBuilder::Property
    6060#define TreePropertyList typename TreeBuilder::PropertyList
     61
     62COMPILE_ASSERT(LastUntaggedToken < 64, LessThan64UntaggedTokens);
    6163
    6264// This matches v8
     
    161163    enum FunctionRequirements { FunctionNoRequirements, FunctionNeedsName };
    162164    template <FunctionRequirements, class TreeBuilder> bool parseFunctionInfo(TreeBuilder&, const Identifier*&, TreeFormalParameterList&, TreeFunctionBody&, int& openBrace, int& closeBrace, int& bodyStartLine);
    163     int isBinaryOperator(JSTokenType token);
     165    ALWAYS_INLINE int isBinaryOperator(JSTokenType token);
    164166    bool allowAutomaticSemicolon();
    165167
     
    10301032}
    10311033
    1032 static bool isUnaryOp(JSTokenType token)
    1033 {
    1034     switch (token) {
    1035     case EXCLAMATION:
    1036     case TILDE:
    1037     case MINUS:
    1038     case PLUS:
    1039     case PLUSPLUS:
    1040     case AUTOPLUSPLUS:
    1041     case MINUSMINUS:
    1042     case AUTOMINUSMINUS:
    1043     case TYPEOF:
    1044     case VOIDTOKEN:
    1045     case DELETETOKEN:
    1046         return true;
    1047     default:
    1048         return false;
    1049     }
     1034ALWAYS_INLINE static bool isUnaryOp(JSTokenType token)
     1035{
     1036    return token & UnaryOpTokenFlag;
    10501037}
    10511038
    10521039int JSParser::isBinaryOperator(JSTokenType token)
    10531040{
    1054     switch (token) {
    1055     case OR:
    1056         return 1;
    1057 
    1058     case AND:
    1059         return 2;
    1060 
    1061     case BITOR:
    1062         return 3;
    1063 
    1064     case BITXOR:
    1065         return 4;
    1066 
    1067     case BITAND:
    1068         return 5;
    1069 
    1070     case EQEQ:
    1071     case NE:
    1072     case STREQ:
    1073     case STRNEQ:
    1074         return 6;
    1075 
    1076     case LT:
    1077     case GT:
    1078     case LE:
    1079     case GE:
    1080     case INSTANCEOF:
    1081         return 7;
    1082 
    1083     case INTOKEN:
    1084         // same precedence as the above but needs a validity check
    1085         if (m_allowsIn)
    1086             return 7;
    1087         return 0;
    1088 
    1089     case LSHIFT:
    1090     case RSHIFT:
    1091     case URSHIFT:
    1092         return 8;
    1093 
    1094     case PLUS:
    1095     case MINUS:
    1096         return 9;
    1097 
    1098     case TIMES:
    1099     case DIVIDE:
    1100     case MOD:
    1101         return 10;
    1102 
    1103     default:
    1104         return 0;
    1105     }
     1041    if (m_allowsIn)
     1042        return token & (BinaryOpTokenPrecedenceMask << BinaryOpTokenAllowsInPrecedenceAdditionalShift);
     1043    return token & BinaryOpTokenPrecedenceMask;
    11061044}
    11071045
Note: See TracChangeset for help on using the changeset viewer.