Changeset 112564 in webkit


Ignore:
Timestamp:
Mar 29, 2012 1:16:03 PM (12 years ago)
Author:
barraclough@apple.com
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.
Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r112562 r112564  
     12012-03-29  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Template the Yarr::Interpreter on the character type
     4        https://bugs.webkit.org/show_bug.cgi?id=82637
     5
     6        Reviewed by Sam Weinig.
     7
     8        We should be able to call to the interpreter after having already checked the character type,
     9        without having to re-package the character pointer back up into a string!
     10
     11        * runtime/RegExp.cpp:
     12        (JSC::RegExp::match):
     13        (JSC::RegExp::matchCompareWithInterpreter):
     14            - Don't pass length.
     15        * yarr/Yarr.h:
     16            - moved function declarations to YarrInterpreter.h.
     17        * yarr/YarrInterpreter.cpp:
     18        (Yarr):
     19        (Interpreter):
     20        (JSC::Yarr::Interpreter::InputStream::InputStream):
     21        (InputStream):
     22        (JSC::Yarr::Interpreter::Interpreter):
     23        (JSC::Yarr::interpret):
     24            - templated Interpreter class on CharType.
     25        * yarr/YarrInterpreter.h:
     26        (Yarr):
     27            - added function declarations.
     28
    1292012-03-29  David Kilzer  <ddkilzer@apple.com>
    230
  • trunk/Source/JavaScriptCore/runtime/RegExp.cpp

    r112536 r112564  
    344344    } else
    345345#endif
    346         result = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, s.length(), reinterpret_cast<unsigned*>(offsetVector));
     346        result = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, reinterpret_cast<unsigned*>(offsetVector));
    347347
    348348    // FIXME: The YARR engine should handle unsigned or size_t length matches.
     
    468468    nonReturnedOvector.resize(offsetVectorSize);
    469469    offsetVector = nonReturnedOvector.data();
    470     int r = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, s.length(), reinterpret_cast<unsigned*>(offsetVector));
     470    int r = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, reinterpret_cast<unsigned*>(offsetVector));
    471471#if REGEXP_FUNC_TEST_DATA_GEN
    472472    RegExpFunctionalTestCollector::get()->outputOneTest(this, s, startOffset, offsetVector, result);
     
    510510        interpreterOffsetVector[j] = -1;
    511511
    512     interpreterResult = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, s.length(), interpreterOffsetVector);
     512    interpreterResult = Yarr::interpret(m_regExpBytecode.get(), s, startOffset, interpreterOffsetVector);
    513513
    514514    if (jitResult != interpreterResult)
  • trunk/Source/JavaScriptCore/yarr/Yarr.h

    r108858 r112564  
    6464};
    6565
    66 JS_EXPORT_PRIVATE PassOwnPtr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
    67 JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const UString& input, unsigned start, unsigned length, unsigned* output);
    68 
    6966} } // namespace JSC::Yarr
    7067
  • 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
  • trunk/Source/JavaScriptCore/yarr/YarrInterpreter.h

    r108858 r112564  
    376376};
    377377
     378JS_EXPORT_PRIVATE PassOwnPtr<BytecodePattern> byteCompile(YarrPattern&, BumpPointerAllocator*);
     379JS_EXPORT_PRIVATE unsigned interpret(BytecodePattern*, const UString& input, unsigned start, unsigned* output);
     380unsigned interpret(BytecodePattern*, const LChar* input, unsigned length, unsigned start, unsigned* output);
     381unsigned interpret(BytecodePattern*, const UChar* input, unsigned length, unsigned start, unsigned* output);
     382
    378383} } // namespace JSC::Yarr
    379384
  • trunk/Source/WebCore/ChangeLog

    r112559 r112564  
     12012-03-29  Gavin Barraclough  <barraclough@apple.com>
     2
     3        Template the Yarr::Interpreter on the character type
     4        https://bugs.webkit.org/show_bug.cgi?id=82637
     5
     6        Reviewed by Sam Weinig.
     7
     8        We should be able to call to the interpreter after having already checked the character type,
     9        without having to re-package the character pointer back up into a string!
     10
     11        * inspector/ContentSearchUtils.cpp:
     12        (WebCore::ContentSearchUtils::findMagicComment):
     13        * platform/text/RegularExpression.cpp:
     14        (WebCore::RegularExpression::match):
     15            - Don't pass length.
     16
    1172012-03-29  Sheriff Bot  <webkit.review.bot@gmail.com>
    218
  • trunk/Source/WebCore/inspector/ContentSearchUtils.cpp

    r111005 r112564  
    153153    Vector<int, 4> matches;
    154154    matches.resize(4);
    155     unsigned result = JSC::Yarr::interpret(bytecodePattern.get(), JSC::UString(content.impl()), 0, content.length(), reinterpret_cast<unsigned*>(matches.data()));
     155    unsigned result = JSC::Yarr::interpret(bytecodePattern.get(), JSC::UString(content.impl()), 0, reinterpret_cast<unsigned*>(matches.data()));
    156156    if (result == JSC::Yarr::offsetNoMatch)
    157157        return String();
  • trunk/Source/WebCore/platform/text/RegularExpression.cpp

    r108874 r112564  
    113113    unsigned result;
    114114    if (str.length() <= INT_MAX)
    115         result = JSC::Yarr::interpret(d->m_regExpByteCode.get(), JSC::UString(str.impl()), startFrom, str.length(), offsetVector);
     115        result = JSC::Yarr::interpret(d->m_regExpByteCode.get(), JSC::UString(str.impl()), startFrom, offsetVector);
    116116    else {
    117117        // This code can't handle unsigned offsets. Limit our processing to strings with offsets that
Note: See TracChangeset for help on using the changeset viewer.