Ignore:
Timestamp:
Mar 29, 2012, 1:16:03 PM (13 years ago)
Author:
[email protected]
Message:

Template the Yarr::Interpreter on the character type
https://bugs.webkit.org/show_bug.cgi?id=82637

Reviewed by Sam Weinig.

We should be able to call to the interpreter after having already checked the character type,
without having to re-package the character pointer back up into a string!

../JavaScriptCore:

  • runtime/RegExp.cpp:

(JSC::RegExp::match):
(JSC::RegExp::matchCompareWithInterpreter):

  • Don't pass length.
  • yarr/Yarr.h:
    • moved function declarations to YarrInterpreter.h.
  • yarr/YarrInterpreter.cpp:

(Yarr):
(Interpreter):
(JSC::Yarr::Interpreter::InputStream::InputStream):
(InputStream):
(JSC::Yarr::Interpreter::Interpreter):
(JSC::Yarr::interpret):

  • templated Interpreter class on CharType.
  • yarr/YarrInterpreter.h:

(Yarr):

  • added function declarations.

../WebCore:

  • inspector/ContentSearchUtils.cpp:

(WebCore::ContentSearchUtils::findMagicComment):

  • platform/text/RegularExpression.cpp:

(WebCore::RegularExpression::match):

  • Don't pass length.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/yarr/YarrInterpreter.cpp

    r112143 r112564  
    4343namespace JSC { namespace Yarr {
    4444
     45template<typename CharType>
    4546class Interpreter {
    4647public:
     
    171172    }
    172173
    173     // This class is a placeholder for future character iterator, current
    174     // proposed name StringConstCharacterIterator.
    175     class CharAccess {
    176     public:
    177         CharAccess(const UString& s)
    178         {
    179             if (s.is8Bit()) {
    180                 m_charSize = Char8;
    181                 m_ptr.ptr8 = s.characters8();
    182             } else {
    183                 m_charSize = Char16;
    184                 m_ptr.ptr16 = s.characters16();
    185             }
    186         }
    187 
    188         CharAccess(const LChar* ptr)
    189             : m_charSize(Char8)
    190         {
    191             m_ptr.ptr8 = ptr;
    192         }
    193 
    194         CharAccess(const UChar* ptr)
    195             : m_charSize(Char16)
    196         {
    197             m_ptr.ptr16 = ptr;
    198         }
    199 
    200         ~CharAccess()
    201         {
    202         }
    203 
    204         inline UChar operator[](unsigned index)
    205         {
    206             if (m_charSize == Char8)
    207                 return m_ptr.ptr8[index];
    208             return m_ptr.ptr16[index];
    209         }
    210 
    211     private:
    212         union {
    213             const LChar* ptr8;
    214             const UChar* ptr16;
    215         } m_ptr;
    216         YarrCharSize m_charSize;
    217     };
    218 
    219174    class InputStream {
    220175    public:
    221         InputStream(const UString& input, unsigned start, unsigned length)
     176        InputStream(const CharType* input, unsigned start, unsigned length)
    222177            : input(input)
    223178            , pos(start)
     
    333288
    334289    private:
    335         CharAccess input;
     290        const CharType* input;
    336291        unsigned pos;
    337292        unsigned length;
     
    14901445    }
    14911446
    1492     Interpreter(BytecodePattern* pattern, unsigned* output, const UString input, unsigned start, unsigned length)
     1447    Interpreter(BytecodePattern* pattern, unsigned* output, const CharType* input, unsigned length, unsigned start)
    14931448        : pattern(pattern)
    14941449        , output(output)
     
    19801935}
    19811936
    1982 unsigned interpret(BytecodePattern* bytecode, const UString& input, unsigned start, unsigned length, unsigned* output)
     1937unsigned interpret(BytecodePattern* bytecode, const UString& input, unsigned start, unsigned* output)
    19831938{
    1984     return Interpreter(bytecode, output, input, start, length).interpret();
     1939    if (input.is8Bit())
     1940        return Interpreter<LChar>(bytecode, output, input.characters8(), input.length(), start).interpret();
     1941    return Interpreter<UChar>(bytecode, output, input.characters16(), input.length(), start).interpret();
    19851942}
    19861943
    1987 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoPatternCharacter);
    1988 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoCharacterClass);
    1989 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoBackReference);
    1990 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoAlternative) == (YarrStackSpaceForBackTrackInfoAlternative * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoAlternative);
    1991 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoParentheticalAssertion) == (YarrStackSpaceForBackTrackInfoParentheticalAssertion * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheticalAssertion);
    1992 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoParenthesesOnce) == (YarrStackSpaceForBackTrackInfoParenthesesOnce * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParenthesesOnce);
    1993 COMPILE_ASSERT(sizeof(Interpreter::BackTrackInfoParentheses) == (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheses);
     1944unsigned interpret(BytecodePattern* bytecode, const LChar* input, unsigned length, unsigned start, unsigned* output)
     1945{
     1946    return Interpreter<LChar>(bytecode, output, input, length, start).interpret();
     1947}
     1948
     1949unsigned interpret(BytecodePattern* bytecode, const UChar* input, unsigned length, unsigned start, unsigned* output)
     1950{
     1951    return Interpreter<UChar>(bytecode, output, input, length, start).interpret();
     1952}
     1953
     1954// These should be the same for both UChar & LChar.
     1955COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoPatternCharacter) == (YarrStackSpaceForBackTrackInfoPatternCharacter * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoPatternCharacter);
     1956COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoCharacterClass) == (YarrStackSpaceForBackTrackInfoCharacterClass * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoCharacterClass);
     1957COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoBackReference) == (YarrStackSpaceForBackTrackInfoBackReference * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoBackReference);
     1958COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoAlternative) == (YarrStackSpaceForBackTrackInfoAlternative * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoAlternative);
     1959COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParentheticalAssertion) == (YarrStackSpaceForBackTrackInfoParentheticalAssertion * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheticalAssertion);
     1960COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParenthesesOnce) == (YarrStackSpaceForBackTrackInfoParenthesesOnce * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParenthesesOnce);
     1961COMPILE_ASSERT(sizeof(Interpreter<UChar>::BackTrackInfoParentheses) == (YarrStackSpaceForBackTrackInfoParentheses * sizeof(uintptr_t)), CheckYarrStackSpaceForBackTrackInfoParentheses);
    19941962
    19951963
Note: See TracChangeset for help on using the changeset viewer.