Ignore:
Timestamp:
Jul 4, 2009, 7:21:30 AM (16 years ago)
Author:
[email protected]
Message:

2009-07-03 Yong Li <[email protected]>

Reviewed by Maciej Stachowiak (and revised slightly)

RegExp::match to be optimized
https://bugs.webkit.org/show_bug.cgi?id=26957

Allow regexp matching to use Vectors with inline capacity instead of
allocating a new ovector buffer every time.


~5% speedup on SunSpider string-unpack-code test, 0.3% on SunSpider overall.

  • runtime/RegExp.cpp: (JSC::RegExp::match):
  • runtime/RegExp.h:
  • runtime/RegExpConstructor.cpp: (JSC::RegExpConstructorPrivate::RegExpConstructorPrivate): (JSC::RegExpConstructorPrivate::lastOvector): (JSC::RegExpConstructorPrivate::tempOvector): (JSC::RegExpConstructorPrivate::changeLastOvector): (JSC::RegExpConstructor::performMatch): (JSC::RegExpMatchesArray::RegExpMatchesArray): (JSC::RegExpMatchesArray::fillArrayInstance): (JSC::RegExpConstructor::getBackref): (JSC::RegExpConstructor::getLastParen): (JSC::RegExpConstructor::getLeftContext): (JSC::RegExpConstructor::getRightContext):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncSplit):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/RegExp.cpp

    r44224 r45545  
    22 *  Copyright (C) 1999-2001, 2004 Harri Porten ([email protected])
    33 *  Copyright (c) 2007, 2008 Apple Inc. All rights reserved.
     4 *  Copyright (C) 2009 Torch Mobile, Inc.
    45 *
    56 *  This library is free software; you can redistribute it and/or
     
    111112}
    112113
    113 int RegExp::match(const UString& s, int startOffset, OwnArrayPtr<int>* ovector)
     114int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector)
    114115{
    115116    if (startOffset < 0)
     
    127128#endif
    128129        int offsetVectorSize = (m_numSubpatterns + 1) * 3; // FIXME: should be 2 - but adding temporary fallback to pcre.
    129         int* offsetVector = new int [offsetVectorSize];
     130        int* offsetVector;
     131        Vector<int, 32> nonReturnedOvector;
     132        if (ovector) {
     133            ovector->resize(offsetVectorSize);
     134            offsetVector = ovector->data();
     135        } else {
     136            nonReturnedOvector.resize(offsetVectorSize);
     137            offsetVector = nonReturnedOvector.data();
     138        }
     139
    130140        ASSERT(offsetVector);
    131141        for (int j = 0; j < offsetVectorSize; ++j)
    132142            offsetVector[j] = -1;
    133143
    134         OwnArrayPtr<int> nonReturnedOvector;
    135         if (!ovector)
    136             nonReturnedOvector.set(offsetVector);
    137         else
    138             ovector->set(offsetVector);
    139144
    140145#if ENABLE(YARR_JIT)
     
    178183}
    179184
    180 int RegExp::match(const UString& s, int startOffset, OwnArrayPtr<int>* ovector)
     185int RegExp::match(const UString& s, int startOffset, Vector<int, 32>* ovector)
    181186{
    182187    if (startOffset < 0)
     
    191196    if (m_wrecFunction) {
    192197        int offsetVectorSize = (m_numSubpatterns + 1) * 2;
    193         int* offsetVector = new int [offsetVectorSize];
     198        int* offsetVector;
     199        Vector<int, 32> nonReturnedOvector;
     200        if (ovector) {
     201            ovector->resize(offsetVectorSize);
     202            offsetVector = ovector->data();
     203        } else {
     204            nonReturnedOvector.resize(offsetVectorSize);
     205            offsetVector = nonReturnedOvector.data();
     206        }
    194207        ASSERT(offsetVector);
    195208        for (int j = 0; j < offsetVectorSize; ++j)
    196209            offsetVector[j] = -1;
    197 
    198         OwnArrayPtr<int> nonReturnedOvector;
    199         if (!ovector)
    200             nonReturnedOvector.set(offsetVector);
    201         else
    202             ovector->set(offsetVector);
    203210
    204211        int result = m_wrecFunction(s.data(), startOffset, s.size(), offsetVector);
     
    227234        } else {
    228235            offsetVectorSize = (m_numSubpatterns + 1) * 3;
    229             offsetVector = new int [offsetVectorSize];
    230             ovector->set(offsetVector);
     236            ovector->resize(offsetVectorSize);
     237            offsetVector = ovector->data();
    231238        }
    232239
Note: See TracChangeset for help on using the changeset viewer.