Changeset 27702 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Nov 11, 2007, 8:27:33 PM (18 years ago)
Author:
[email protected]
Message:

Reviewed by Sam Weinig.


Fixed http://bugs.webkit.org/show_bug.cgi?id=15902
15% of string-validate-input.js is spent compiling the same regular expression


Store a compiled representation of the regular expression in the AST.


Only a .2% SunSpider speedup overall, but a 10.6% speedup on
string-validate-input.js.

  • kjs/nodes.cpp: (KJS::RegExpNode::evaluate):
  • kjs/nodes.h: (KJS::RegExpNode::):
  • kjs/nodes2string.cpp: (KJS::RegExpNode::streamTo):
  • kjs/regexp.cpp: (KJS::RegExp::flags):
  • kjs/regexp.h: (KJS::RegExp::pattern):
  • kjs/regexp_object.cpp: (KJS::RegExpObjectImp::construct): (KJS::RegExpObjectImp::createRegExpImp):
  • kjs/regexp_object.h:
Location:
trunk/JavaScriptCore
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r27698 r27702  
     12007-11-11  Geoffrey Garen  <[email protected]>
     2
     3        Reviewed by Sam Weinig.
     4       
     5        Fixed http://bugs.webkit.org/show_bug.cgi?id=15902
     6        15% of string-validate-input.js is spent compiling the same regular expression
     7       
     8        Store a compiled representation of the regular expression in the AST.
     9       
     10        Only a .2% SunSpider speedup overall, but a 10.6% speedup on
     11        string-validate-input.js.
     12
     13        * kjs/nodes.cpp:
     14        (KJS::RegExpNode::evaluate):
     15        * kjs/nodes.h:
     16        (KJS::RegExpNode::):
     17        * kjs/nodes2string.cpp:
     18        (KJS::RegExpNode::streamTo):
     19        * kjs/regexp.cpp:
     20        (KJS::RegExp::flags):
     21        * kjs/regexp.h:
     22        (KJS::RegExp::pattern):
     23        * kjs/regexp_object.cpp:
     24        (KJS::RegExpObjectImp::construct):
     25        (KJS::RegExpObjectImp::createRegExpImp):
     26        * kjs/regexp_object.h:
     27
    1282007-11-11  Oliver Hunt  <[email protected]>
    229
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r27695 r27702  
    454454JSValue* RegExpNode::evaluate(ExecState* exec)
    455455{
    456   List list;
    457   list.append(jsOwnedString(m_pattern));
    458   list.append(jsOwnedString(m_flags));
    459 
    460   JSObject* reg = exec->lexicalInterpreter()->builtinRegExp();
    461   return reg->construct(exec, list);
     456    return exec->lexicalInterpreter()->builtinRegExp()->createRegExpImp(exec, m_regExp);
    462457}
    463458
  • trunk/JavaScriptCore/kjs/nodes.h

    r27695 r27702  
    2929#include "Parser.h"
    3030#include "internal.h"
     31#include "RegExp.h"
    3132#include "SymbolTable.h"
    3233#include <wtf/ListRefPtr.h>
     
    271272  public:
    272273    RegExpNode(const UString& pattern, const UString& flags) KJS_FAST_CALL
    273       : m_pattern(pattern), m_flags(flags) { }
    274     virtual JSValue* evaluate(ExecState*) KJS_FAST_CALL;
     274        : m_regExp(new RegExp(pattern, flags))
     275    {
     276    }
     277    JSValue* evaluate(ExecState*) KJS_FAST_CALL;
    275278    virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
    276279    virtual Precedence precedence() const { return PrecPrimary; }
    277280  private:
    278     UString m_pattern;
    279     UString m_flags;
     281    RefPtr<RegExp> m_regExp;
    280282  };
    281283
  • trunk/JavaScriptCore/kjs/nodes2string.cpp

    r27695 r27702  
    291291void RegExpNode::streamTo(SourceStream& s) const
    292292{
    293     s << '/' <<  m_pattern << '/' << m_flags;
     293    s << '/' <<  m_regExp->pattern() << '/' << m_regExp->flags();
    294294}
    295295
  • trunk/JavaScriptCore/kjs/regexp.cpp

    r27686 r27702  
    22/*
    33 *  This file is part of the KDE libraries
    4  *  Copyright (C) 1999-2001,2004 Harri Porten ([email protected])
     4 *  Copyright (C) 1999-2001, 2004 Harri Porten ([email protected])
     5 *  Copyright (c) 2007, Apple Inc.
    56 *
    67 *  This library is free software; you can redistribute it and/or
     
    3435  : m_refCount(0)
    3536  , m_pattern(pattern)
    36   , m_flags(0)
     37  , m_flagBits(0)
    3738  , m_constructionError(0)
    3839  , m_numSubpatterns(0)
    3940{
    40     m_regExp = jsRegExpCompile(reinterpret_cast<const ::UChar*>(m_pattern.data()), m_pattern.size(),
     41    m_regExp = jsRegExpCompile(reinterpret_cast<const ::UChar*>(pattern.data()), pattern.size(),
    4142        JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError);
    4243}
     
    4546  : m_refCount(0)
    4647  , m_pattern(pattern)
    47   , m_flags(0)
     48  , m_flags(flags)
     49  , m_flagBits(0)
    4850  , m_constructionError(0)
    4951  , m_numSubpatterns(0)
     
    5254    // String::match and RegExpImp::match.
    5355    if (flags.find('g') != -1)
    54         m_flags |= Global;
     56        m_flagBits |= Global;
    5557
    5658    // FIXME: Eliminate duplication by adding a way ask a JSRegExp what its flags are?
    5759    JSRegExpIgnoreCaseOption ignoreCaseOption = JSRegExpDoNotIgnoreCase;
    5860    if (flags.find('i') != -1) {
    59         m_flags |= IgnoreCase;
     61        m_flagBits |= IgnoreCase;
    6062        ignoreCaseOption = JSRegExpIgnoreCase;
    6163    }
     
    6365    JSRegExpMultilineOption multilineOption = JSRegExpSingleLine;
    6466    if (flags.find('m') != -1) {
    65         m_flags |= Multiline;
     67        m_flagBits |= Multiline;
    6668        multilineOption = JSRegExpMultiline;
    6769    }
    6870   
    69     m_regExp = jsRegExpCompile(reinterpret_cast<const ::UChar*>(m_pattern.data()), m_pattern.size(),
     71    m_regExp = jsRegExpCompile(reinterpret_cast<const ::UChar*>(pattern.data()), pattern.size(),
    7072        ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError);
    7173}
  • trunk/JavaScriptCore/kjs/regexp.h

    r27686 r27702  
    4747    int refCount() { return m_refCount; }
    4848
    49     bool global() const { return m_flags & Global; }
    50     bool ignoreCase() const { return m_flags & IgnoreCase; }
    51     bool multiline() const { return m_flags & Multiline; }
     49    bool global() const { return m_flagBits & Global; }
     50    bool ignoreCase() const { return m_flagBits & IgnoreCase; }
     51    bool multiline() const { return m_flagBits & Multiline; }
     52
    5253    const UString& pattern() const { return m_pattern; }
     54    const UString& flags() const { return m_flags; }
    5355
    5456    bool isValid() const { return !m_constructionError; }
     
    6466   
    6567    // Data supplied by caller.
    66     UString m_pattern;
    67     int m_flags;
     68    UString m_pattern; // FIXME: Just decompile m_regExp instead of storing this.
     69    UString m_flags; // FIXME: Just decompile m_regExp instead of storing this.
     70    int m_flagBits;
    6871
    6972    // Data supplied by PCRE.
  • trunk/JavaScriptCore/kjs/regexp_object.cpp

    r27573 r27702  
    449449  UString pattern = arg0->isUndefined() ? UString("") : arg0->toString(exec);
    450450  UString flags = arg1->isUndefined() ? UString("") : arg1->toString(exec);
    451   RefPtr<RegExp> regExp = new RegExp(pattern, flags);
    452 
    453   return regExp->isValid()
    454     ? new RegExpImp(static_cast<RegExpPrototype*>(exec->lexicalInterpreter()->builtinRegExpPrototype()), regExp.release())
    455     : throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
     451 
     452  return createRegExpImp(exec, new RegExp(pattern, flags));
     453}
     454
     455JSObject* RegExpObjectImp::createRegExpImp(ExecState* exec, PassRefPtr<RegExp> regExp)
     456{
     457    return regExp->isValid()
     458        ? new RegExpImp(static_cast<RegExpPrototype*>(exec->lexicalInterpreter()->builtinRegExpPrototype()), regExp)
     459        : throwError(exec, SyntaxError, UString("Invalid regular expression: ").append(regExp->errorMessage()));
    456460}
    457461
  • trunk/JavaScriptCore/kjs/regexp_object.h

    r27571 r27702  
    8686        virtual bool implementsConstruct() const;
    8787        virtual JSObject* construct(ExecState*, const List&);
     88        JSObject* createRegExpImp(ExecState*, PassRefPtr<RegExp>);
    8889        virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&);
    8990        virtual void put(ExecState*, const Identifier&, JSValue*, int attributes = None);
Note: See TracChangeset for help on using the changeset viewer.