Changeset 36244 in webkit for trunk/JavaScriptCore/kjs/regexp.cpp


Ignore:
Timestamp:
Sep 6, 2008, 10:44:58 PM (17 years ago)
Author:
[email protected]
Message:

Merge squirrelfish-extreme to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/regexp.cpp

    r35027 r36244  
    2222#include "regexp.h"
    2323
     24#include "CTI.h"
    2425#include "lexer.h"
    2526#include <pcre/pcre.h>
     
    3233namespace KJS {
    3334
    34 inline RegExp::RegExp(const UString& pattern)
     35
     36
     37inline RegExp::RegExp(ExecState* exec, const UString& pattern)
    3538    : m_pattern(pattern)
    3639    , m_flagBits(0)
     40    , m_regExp(0)
    3741    , m_constructionError(0)
    3842    , m_numSubpatterns(0)
    3943{
    40     m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
    41         JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError);
     44#if ENABLE(WREC)
     45    if (!(m_wrecFunction = (WRECFunction)CTI::compileRegExp(exec, pattern, &m_numSubpatterns, &m_constructionError)))
     46#else
     47    UNUSED_PARAM(exec);
     48#endif
     49    {
     50        m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
     51            JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError);
     52    }
    4253}
    4354
    44 PassRefPtr<RegExp> RegExp::create(const UString& pattern)
     55PassRefPtr<RegExp> RegExp::create(ExecState* exec, const UString& pattern)
    4556{
    46     return adoptRef(new RegExp(pattern));
     57    return adoptRef(new RegExp(exec, pattern));
    4758}
    4859
    49 inline RegExp::RegExp(const UString& pattern, const UString& flags)
     60inline RegExp::RegExp(ExecState* exec, const UString& pattern, const UString& flags)
    5061    : m_pattern(pattern)
    5162    , m_flags(flags)
    5263    , m_flagBits(0)
     64    , m_regExp(0)
    5365    , m_constructionError(0)
    5466    , m_numSubpatterns(0)
     
    7284    }
    7385
    74     m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
    75         ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
     86#if ENABLE(WREC)
     87    if (!(m_wrecFunction = (WRECFunction)CTI::compileRegExp(exec, pattern, &m_numSubpatterns, &m_constructionError, (m_flagBits & IgnoreCase), (m_flagBits & Multiline))))
     88#else
     89    UNUSED_PARAM(exec);
     90#endif
     91    {
     92        m_regExp = jsRegExpCompile(reinterpret_cast<const UChar*>(pattern.data()), pattern.size(),
     93            ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
     94    }
    7695}
    7796
    78 PassRefPtr<RegExp> RegExp::create(const UString& pattern, const UString& flags)
     97PassRefPtr<RegExp> RegExp::create(ExecState* exec, const UString& pattern, const UString& flags)
    7998{
    80     return adoptRef(new RegExp(pattern, flags));
     99    return adoptRef(new RegExp(exec, pattern, flags));
    81100}
    82101
     
    84103{
    85104    jsRegExpFree(m_regExp);
     105#if ENABLE(WREC)
     106    if (m_wrecFunction)
     107        fastFree(reinterpret_cast<void*>(m_wrecFunction));
     108#endif
    86109}
    87110
     
    96119        return -1;
    97120
    98     if (!m_regExp)
    99         return -1;
     121#if ENABLE(WREC)
     122    if (m_wrecFunction) {
     123        int offsetVectorSize = (m_numSubpatterns + 1) * 2;
     124        int* offsetVector = new int [offsetVectorSize];
     125        for (int j = 0; j < offsetVectorSize; ++j)
     126            offsetVector[j] = -1;
    100127
    101     // Set up the offset vector for the result.
    102     // First 2/3 used for result, the last third used by PCRE.
    103     int* offsetVector;
    104     int offsetVectorSize;
    105     int fixedSizeOffsetVector[3];
    106     if (!ovector) {
    107         offsetVectorSize = 3;
    108         offsetVector = fixedSizeOffsetVector;
    109     } else {
    110         offsetVectorSize = (m_numSubpatterns + 1) * 3;
    111         offsetVector = new int [offsetVectorSize];
    112         ovector->set(offsetVector);
     128        OwnArrayPtr<int> nonReturnedOvector;
     129        if (!ovector)
     130            nonReturnedOvector.set(offsetVector);
     131        else
     132            ovector->set(offsetVector);
     133
     134        int result = m_wrecFunction(s.data(), i, s.size(), offsetVector);
     135
     136        if (result < 0) {
     137#ifndef NDEBUG
     138            // TODO: define up a symbol, rather than magic -1
     139            if (result != -1)
     140                fprintf(stderr, "jsRegExpExecute failed with result %d\n", result);
     141#endif
     142            if (ovector)
     143                ovector->clear();
     144        }
     145        return result;
     146    } else
     147#endif
     148    if (m_regExp) {
     149        // Set up the offset vector for the result.
     150        // First 2/3 used for result, the last third used by PCRE.
     151        int* offsetVector;
     152        int offsetVectorSize;
     153        int fixedSizeOffsetVector[3];
     154        if (!ovector) {
     155            offsetVectorSize = 3;
     156            offsetVector = fixedSizeOffsetVector;
     157        } else {
     158            offsetVectorSize = (m_numSubpatterns + 1) * 3;
     159            offsetVector = new int [offsetVectorSize];
     160            ovector->set(offsetVector);
     161        }
     162
     163        int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize);
     164   
     165        if (numMatches < 0) {
     166#ifndef NDEBUG
     167            if (numMatches != JSRegExpErrorNoMatch)
     168                fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);
     169#endif
     170            if (ovector)
     171                ovector->clear();
     172            return -1;
     173        }
     174
     175        return offsetVector[0];
    113176    }
    114177
    115     int numMatches = jsRegExpExecute(m_regExp, reinterpret_cast<const UChar*>(s.data()), s.size(), i, offsetVector, offsetVectorSize);
    116 
    117     if (numMatches < 0) {
    118 #ifndef NDEBUG
    119         if (numMatches != JSRegExpErrorNoMatch)
    120             fprintf(stderr, "jsRegExpExecute failed with result %d\n", numMatches);
    121 #endif
    122         if (ovector)
    123             ovector->clear();
    124         return -1;
    125     }
    126 
    127     return offsetVector[0];
     178    return -1;
    128179}
    129180
Note: See TracChangeset for help on using the changeset viewer.