Ignore:
Timestamp:
Nov 6, 2012, 2:01:51 PM (13 years ago)
Author:
[email protected]
Message:

Lexer::scanRegExp, create 8 bit pattern and flag Identifiers from 16 bit source when possible
https://bugs.webkit.org/show_bug.cgi?id=101013

Reviewed by Darin Adler.

Changed scanRegExp so that it will create 8 bit identifiers from 8 bit sources and from 16 bit sources
whan all the characters are 8 bit. Using two templated helpers, the "is all 8 bit" check is only performed
on 16 bit sources. The first helper is orCharacter() that will accumulate the or value of all characters
only for 16 bit sources. Replaced the helper Lexer::makeIdentifierSameType() with Lexer::makeRightSizedIdentifier().

  • parser/Lexer.cpp:

(JSC::orCharacter<LChar>): Explicit template that serves as a placeholder.
(JSC::orCharacter<UChar>): Explicit template that actually or accumulates characters.
(JSC::Lexer::scanRegExp):

  • parser/Lexer.h:

(Lexer):
(JSC::Lexer::makeRightSizedIdentifier<LChar>): New template that always creates an 8 bit Identifier.
(JSC::Lexer::makeRightSizedIdentifier<UChar>): New template that creates an 8 bit Identifier for 8 bit
data in a 16 bit source.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Lexer.cpp

    r132853 r133668  
    16871687
    16881688template <typename T>
     1689static inline void orCharacter(UChar&, UChar);
     1690
     1691template <>
     1692inline void orCharacter<LChar>(UChar&, UChar) { }
     1693
     1694template <>
     1695inline void orCharacter<UChar>(UChar& orAccumulator, UChar character)
     1696{
     1697    orAccumulator |= character;
     1698}
     1699
     1700template <typename T>
    16891701bool Lexer<T>::scanRegExp(const Identifier*& pattern, const Identifier*& flags, UChar patternPrefix)
    16901702{
     
    16931705    bool lastWasEscape = false;
    16941706    bool inBrackets = false;
     1707    UChar charactersOredTogether = 0;
    16951708
    16961709    if (patternPrefix) {
     
    17151728
    17161729        record16(prev);
     1730        orCharacter<T>(charactersOredTogether, prev);
    17171731
    17181732        if (lastWasEscape) {
     
    17341748    }
    17351749
    1736     pattern = makeIdentifierSameType(m_buffer16.data(), m_buffer16.size());
     1750    pattern = makeRightSizedIdentifier(m_buffer16.data(), m_buffer16.size(), charactersOredTogether);
     1751
    17371752    m_buffer16.resize(0);
     1753    charactersOredTogether = 0;
    17381754
    17391755    while (isIdentPart(m_current)) {
    17401756        record16(m_current);
    1741         shift();
    1742     }
    1743 
    1744     flags = makeIdentifierSameType(m_buffer16.data(), m_buffer16.size());
     1757        orCharacter<T>(charactersOredTogether, m_current);
     1758        shift();
     1759    }
     1760
     1761    flags = makeRightSizedIdentifier(m_buffer16.data(), m_buffer16.size(), charactersOredTogether);
    17451762    m_buffer16.resize(0);
    17461763
Note: See TracChangeset for help on using the changeset viewer.