Changeset 27571 in webkit for trunk/JavaScriptCore/kjs/regexp.h


Ignore:
Timestamp:
Nov 7, 2007, 9:18:39 AM (18 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

Reviewed by Darin Adler.


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

Put RegExpImp properties into a static hashtable to avoid a slew of
PropertyMap churn when creating a RegExpImp.


Factored important bits of regular expression implementation out of
RegExpImp (the JS object) and into RegExp (the PCRE wrapper class),
making RegExp a ref-counted class. (This will help later.)

Removed PCRE_POSIX support because I didn't quite know how to test it
and keep it working with these changes.


1.1% SunSpider speedup. 5.8% speedup on string-validate-input.js.

  • kjs/regexp.h: A few interface changes:
  1. Renamed "subpatterns()" => "numSubpatterns()"
  2. Made flag enumeration private and replaced it with public getters for specific flags.
  3. Made RegExp ref-counted so RegExps can be shared by RegExpImps.
  4. Made RegExp take a string of flags instead of an int, eliminating duplicated flag parsing code elsewhere.
  • kjs/regexp_object.cpp: (KJS::RegExpProtoFunc::callAsFunction): For RegExp.compile:
  • Fixed a bug where compile(undefined) would throw an exception.
  • Removed some now-redundant code.
  • Used RegExp sharing to eliminate an allocation and a bunch of PropertyMap thrash. (Not a big win since compile is a deprecated function. I mainly did this to test the plubming.)

LayoutTests:

Reviewed by Darin Adler.


Beefed up the RegExp.compile testcase to cover a mistake in the
original check-in and a mistake I made while developing my new patch.

  • fast/js/resources/regexp-compile.js:
File:
1 edited

Legend:

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

    r27419 r27571  
    2323#define KJS_REGEXP_H
    2424
     25#include "ustring.h"
     26#include <pcre.h>
    2527#include <sys/types.h>
    26 
    27 #if !USE(POSIX_REGEX)
    28 #include <pcre.h>
    29 #else
    30 // POSIX regex - not so good.
    31 extern "C" { // bug with some libc5 distributions
    32 #include <regex.h>
    33 }
    34 #endif
    35 
    36 #include "ustring.h"
    3728#include <wtf/OwnArrayPtr.h>
    3829
     
    4031
    4132  class RegExp : Noncopyable {
     33  private:
     34    enum {
     35        Global = 1,
     36        IgnoreCase = 2,
     37        Multiline = 4
     38    };
     39
    4240  public:
    43     enum { None = 0, Global = 1, IgnoreCase = 2, Multiline = 4 };
     41    RegExp(const UString& pattern);
     42    RegExp(const UString& pattern, const UString& flags);
     43    ~RegExp();
     44   
     45    void ref() { ++m_refCount; }
     46    void deref() { if (--m_refCount == 0) delete this; }
     47    int refCount() { return m_refCount; }
    4448
    45     RegExp(const UString& pattern, int flags = None);
    46     ~RegExp();
     49    bool global() const { return m_flags & Global; }
     50    bool ignoreCase() const { return m_flags & IgnoreCase; }
     51    bool multiline() const { return m_flags & Multiline; }
     52    const UString& pattern() const { return m_pattern; }
    4753
    48     int flags() const { return m_flags; }
    4954    bool isValid() const { return !m_constructionError; }
    5055    const char* errorMessage() const { return m_constructionError; }
    5156
    5257    int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
    53     unsigned subPatterns() const { return m_numSubPatterns; }
     58    unsigned numSubpatterns() const { return m_numSubpatterns; }
    5459
    5560  private:
    56 #if !USE(POSIX_REGEX)
    57     JSRegExp* m_regex;
    58 #else
    59     regex_t m_regex;
    60 #endif
     61    void compile();
     62   
     63    int m_refCount;
     64   
     65    // Data supplied by caller.
     66    UString m_pattern;
    6167    int m_flags;
     68
     69    // Data supplied by PCRE.
     70    JSRegExp* m_regExp;
    6271    char* m_constructionError;
    63     unsigned m_numSubPatterns;
     72    unsigned m_numSubpatterns;
    6473  };
    6574
Note: See TracChangeset for help on using the changeset viewer.