Ignore:
Timestamp:
Mar 21, 2012, 1:55:41 PM (13 years ago)
Author:
[email protected]
Message:

RegExpMatchesArray should not copy the ovector
https://bugs.webkit.org/show_bug.cgi?id=81742

Reviewed by Michael Saboff.

Currently, all RegExpMatchesArray object contain Vector<int, 32>, used to hold any sub-pattern results.
This makes allocation/construction/destruction of these objects more expensive. Instead, just store the
main match, and recreate the sub-pattern ranges only if necessary (these are often only used for grouping,
and the results never accessed).
If the main match (index 0) of the RegExpMatchesArray is accessed, reify that value alone.

  • dfg/DFGOperations.cpp:
    • RegExpObject match renamed back to test (test returns a bool).
  • runtime/RegExpConstructor.cpp:

(JSC):

  • Removed RegExpResult, RegExpMatchesArray constructor, destroy method.

(JSC::RegExpMatchesArray::finishCreation):

  • Removed RegExpConstructorPrivate parameter.

(JSC::RegExpMatchesArray::reifyAllProperties):

  • (Was fillArrayInstance) Reify all properties of the RegExpMatchesArray. If there are sub-pattern properties, the RegExp is re-run to generate their values.

(JSC::RegExpMatchesArray::reifyMatchProperty):

  • Reify just the match (index 0) property of the RegExpMatchesArray.
  • runtime/RegExpConstructor.h:

(RegExpConstructor):
(JSC::RegExpConstructor::performMatch):

  • performMatch now returns a MatchResult, rather than using out-parameters.
  • runtime/RegExpMatchesArray.h:

(JSC::RegExpMatchesArray::RegExpMatchesArray):

  • Moved from .cpp, stores the input/regExp/result to use when lazily reifying properties.

(RegExpMatchesArray):
(JSC::RegExpMatchesArray::create):

  • Now passed the input string matched against, the RegExp, and the MatchResult.

(JSC::RegExpMatchesArray::reifyAllPropertiesIfNecessary):
(JSC::RegExpMatchesArray::reifyMatchPropertyIfNecessary):

  • Helpers to conditionally reify properties.

(JSC::RegExpMatchesArray::getOwnPropertySlot):
(JSC::RegExpMatchesArray::getOwnPropertySlotByIndex):
(JSC::RegExpMatchesArray::getOwnPropertyDescriptor):
(JSC::RegExpMatchesArray::put):
(JSC::RegExpMatchesArray::putByIndex):
(JSC::RegExpMatchesArray::deleteProperty):
(JSC::RegExpMatchesArray::deletePropertyByIndex):
(JSC::RegExpMatchesArray::getOwnPropertyNames):
(JSC::RegExpMatchesArray::defineOwnProperty):

  • Changed to use reifyAllPropertiesIfNecessary/reifyMatchPropertyIfNecessary (getOwnPropertySlotByIndex calls reifyMatchPropertyIfNecessary if index is 0).
  • runtime/RegExpObject.cpp:

(JSC::RegExpObject::exec):
(JSC::RegExpObject::match):

  • match now returns a MatchResult.
  • runtime/RegExpObject.h:

(JSC::MatchResult::MatchResult):

  • Added the result of a match is a start & end tuple.

(JSC::MatchResult::failed):

  • A failure is indicated by (notFound, 0).

(JSC::MatchResult::operator bool):

  • Evaluates to false if the match failed.

(JSC::MatchResult::empty):

  • Evaluates to true if the match succeeded with length 0.

(JSC::RegExpObject::test):

  • Now returns a bool.
  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncTest):

  • RegExpObject match renamed back to test (test returns a bool).
  • runtime/StringPrototype.cpp:

(JSC::removeUsingRegExpSearch):
(JSC::replaceUsingRegExpSearch):
(JSC::stringProtoFuncMatch):
(JSC::stringProtoFuncSearch):

  • performMatch now returns a MatchResult, rather than using out-parameters.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/RegExpObject.h

    r111129 r111603  
    2626
    2727namespace JSC {
     28   
     29    struct MatchResult {
     30        ALWAYS_INLINE MatchResult(size_t start, size_t end)
     31            : start(start)
     32            , end(end)
     33        {
     34        }
     35        ALWAYS_INLINE static MatchResult failed()
     36        {
     37            return MatchResult(WTF::notFound, 0);
     38        }
     39        ALWAYS_INLINE operator bool()
     40        {
     41            return start != WTF::notFound;
     42        }
     43        ALWAYS_INLINE bool empty()
     44        {
     45            return start == end;
     46        }
     47        size_t start;
     48        size_t end;
     49    };
    2850   
    2951    class RegExpObject : public JSNonFinalObject {
     
    6890        }
    6991
    70         bool match(ExecState*, JSString* string);
    71         JSValue exec(ExecState*, JSString* string);
     92        bool test(ExecState* exec, JSString* string) { return match(exec, string); }
     93        JSValue exec(ExecState*, JSString*);
    7294
    7395        static bool getOwnPropertySlot(JSCell*, ExecState*, const Identifier& propertyName, PropertySlot&);
     
    96118
    97119    private:
     120        MatchResult match(ExecState*, JSString*);
     121
    98122        WriteBarrier<RegExp> m_regExp;
    99123        WriteBarrier<Unknown> m_lastIndex;
Note: See TracChangeset for help on using the changeset viewer.