source: webkit/trunk/JavaScriptCore/kjs/regexp.h@ 27747

Last change on this file since 27747 was 27702, checked in by [email protected], 18 years ago

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:
  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * Copyright (C) 1999-2000 Harri Porten ([email protected])
4 * Copyright (C) 2007 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22#ifndef KJS_REGEXP_H
23#define KJS_REGEXP_H
24
25#include "ustring.h"
26#include <pcre.h>
27#include <sys/types.h>
28#include <wtf/OwnArrayPtr.h>
29
30namespace KJS {
31
32 class RegExp : Noncopyable {
33 private:
34 enum {
35 Global = 1,
36 IgnoreCase = 2,
37 Multiline = 4
38 };
39
40 public:
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; }
48
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
53 const UString& pattern() const { return m_pattern; }
54 const UString& flags() const { return m_flags; }
55
56 bool isValid() const { return !m_constructionError; }
57 const char* errorMessage() const { return m_constructionError; }
58
59 int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
60 unsigned numSubpatterns() const { return m_numSubpatterns; }
61
62 private:
63 void compile();
64
65 int m_refCount;
66
67 // Data supplied by caller.
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;
71
72 // Data supplied by PCRE.
73 JSRegExp* m_regExp;
74 const char* m_constructionError;
75 unsigned m_numSubpatterns;
76 };
77
78} // namespace
79
80#endif
Note: See TracBrowser for help on using the repository browser.