Ignore:
Timestamp:
Jul 16, 2018, 12:49:11 PM (7 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Make SourceParseMode small
https://bugs.webkit.org/show_bug.cgi?id=187705

Reviewed by Mark Lam.

Each SourceParseMode is distinct. So we do not need to make it a set-style (power of 2 style).
Originally, this is done to make SourceParseModeSet faster because it is critical in our parser.
But we can keep SourceParseModeSet fast by 1U << mode | set. And we can make SourceParseMode
within 5 bits. This reduces the size of UnlinkedCodeBlock from 288 to 280.

  • parser/ParserModes.h:

(JSC::SourceParseModeSet::SourceParseModeSet):
(JSC::SourceParseModeSet::contains):
(JSC::SourceParseModeSet::mergeSourceParseModes):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/ParserModes.h

    r233855 r233860  
    4343enum class FunctionMode { FunctionExpression, FunctionDeclaration, MethodDefinition };
    4444
    45 enum class SourceParseMode : uint32_t {
    46     NormalFunctionMode                = 0b00000000000000000000000000000001,
    47     GeneratorBodyMode                 = 0b00000000000000000000000000000010,
    48     GeneratorWrapperFunctionMode      = 0b00000000000000000000000000000100,
    49     GetterMode                        = 0b00000000000000000000000000001000,
    50     SetterMode                        = 0b00000000000000000000000000010000,
    51     MethodMode                        = 0b00000000000000000000000000100000,
    52     ArrowFunctionMode                 = 0b00000000000000000000000001000000,
    53     AsyncFunctionBodyMode             = 0b00000000000000000000000010000000,
    54     AsyncArrowFunctionBodyMode        = 0b00000000000000000000000100000000,
    55     AsyncFunctionMode                 = 0b00000000000000000000001000000000,
    56     AsyncMethodMode                   = 0b00000000000000000000010000000000,
    57     AsyncArrowFunctionMode            = 0b00000000000000000000100000000000,
    58     ProgramMode                       = 0b00000000000000000001000000000000,
    59     ModuleAnalyzeMode                 = 0b00000000000000000010000000000000,
    60     ModuleEvaluateMode                = 0b00000000000000000100000000000000,
    61     AsyncGeneratorBodyMode            = 0b00000000000000001000000000000000,
    62     AsyncGeneratorWrapperFunctionMode = 0b00000000000000010000000000000000,
    63     AsyncGeneratorWrapperMethodMode   = 0b00000000000000100000000000000000,
    64     GeneratorWrapperMethodMode        = 0b00000000000001000000000000000000,
     45// Keep it less than 32, it means this should be within 5 bits.
     46enum class SourceParseMode : uint8_t {
     47    NormalFunctionMode                = 0,
     48    GeneratorBodyMode                 = 1,
     49    GeneratorWrapperFunctionMode      = 2,
     50    GetterMode                        = 3,
     51    SetterMode                        = 4,
     52    MethodMode                        = 5,
     53    ArrowFunctionMode                 = 6,
     54    AsyncFunctionBodyMode             = 7,
     55    AsyncArrowFunctionBodyMode        = 8,
     56    AsyncFunctionMode                 = 9,
     57    AsyncMethodMode                   = 10,
     58    AsyncArrowFunctionMode            = 11,
     59    ProgramMode                       = 12,
     60    ModuleAnalyzeMode                 = 13,
     61    ModuleEvaluateMode                = 14,
     62    AsyncGeneratorBodyMode            = 15,
     63    AsyncGeneratorWrapperFunctionMode = 16,
     64    AsyncGeneratorWrapperMethodMode   = 17,
     65    GeneratorWrapperMethodMode        = 18,
    6566};
    6667
     
    6869public:
    6970    template<typename... Modes>
    70     SourceParseModeSet(Modes... args)
     71    constexpr SourceParseModeSet(Modes... args)
    7172        : m_mask(mergeSourceParseModes(args...))
    7273    {
    7374    }
    7475
    75     ALWAYS_INLINE bool contains(SourceParseMode mode)
     76    ALWAYS_INLINE constexpr bool contains(SourceParseMode mode)
    7677    {
    77         return static_cast<unsigned>(mode) & m_mask;
     78        return (1U << static_cast<unsigned>(mode)) & m_mask;
    7879    }
    7980
    8081private:
    81     ALWAYS_INLINE static unsigned mergeSourceParseModes(SourceParseMode mode)
     82    ALWAYS_INLINE static constexpr unsigned mergeSourceParseModes(SourceParseMode mode)
    8283    {
    83         return static_cast<unsigned>(mode);
     84        return (1U << static_cast<unsigned>(mode));
    8485    }
    8586
    8687    template<typename... Rest>
    87     ALWAYS_INLINE static unsigned mergeSourceParseModes(SourceParseMode mode, Rest... rest)
     88    ALWAYS_INLINE static constexpr unsigned mergeSourceParseModes(SourceParseMode mode, Rest... rest)
    8889    {
    89         return static_cast<unsigned>(mode) | mergeSourceParseModes(rest...);
     90        return (1U << static_cast<unsigned>(mode)) | mergeSourceParseModes(rest...);
    9091    }
    9192
Note: See TracChangeset for help on using the changeset viewer.