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

Last change on this file since 27686 was 27686, checked in by Darin Adler, 18 years ago

JavaScriptCore:

Reviewed by Sam.

This is a combination of converting to C++, tweaking the API, and adding
some additional optimizations.

Future steps will involve getting rid of the use of UTF-8 completely
(we'll use UTF-16 exclusively instead), eliminating more source files,
and some more speed-ups.

SunSpider says the current round is an 0.9% speed-up overall, and a
5.3% speed-up for regexp.

  • kjs/regexp.cpp: (KJS::RegExp::RegExp): Changed to use the error message without calling strdup on it and to pass the new types and options. (KJS::RegExp::~RegExp): Removed the now-unneeded free of the error message. (KJS::RegExp::match): Pass the new types and options.
  • kjs/regexp.h: Update type of m_constructionError.
  • pcre/AUTHORS: Update to reflect the status of the project -- we don't include the Google parts, and this isn't the PCRE library, per se.
  • pcre/COPYING: Ditto.
  • pcre/dftables.cpp: Copied from JavaScriptCore/pcre/dftables.c. (main): Removed unneeded ctype_digit.
  • pcre/pcre.h: Convert to C++, tweak API a bit. Use UChar instead of JSRegExpChar.
  • pcre/pcre_compile.cpp: Copied from JavaScriptCore/pcre/pcre_compile.c. Moved a lot of private stuff used only within this file here from pcre_internal.h. Renumbered the error codes. (error_text): Use a single string with embedded nulls for the error text (I got this idea from newer versions of PCRE). (check_escape): Changed return type to be enum instead of int. Replaced ctype_digit uses with isASCIIDigit. (is_counted_repeat): Ditto. (read_repeat_counts): Ditto. (first_significant_code): Ditto. (find_fixedlength): Ditto. (could_be_empty_branch): Ditto. (compile_branch): Ditto. Also removed some code that handles changing options. JavaScript doesn't have any of the features that allow options to change. (compile_regex): Updated for change to options parameter. (is_anchored): Ditto. (find_firstassertedchar): Ditto. (jsRegExpCompile): Changed to take separate flags instead of an options int. Also changed to call new/delete instead of pcre_malloc/free. (jsRegExpFree): Ditto.
  • pcre/pcre_exec.cpp: Copied from JavaScriptCore/pcre/pcre_exec.c. Added a case that uses computed goto for the opcode loop, but did not turn it on. Changed the RMATCH macro to handle returns more efficiently by putting the where pointer in the new frame instead of the old one, allowing us to branch to the return with a single statement. Switched to new/delete from pcre_malloc/free. Changed many RRETURN callers to not set the return value since it's already set correctly. Replaced the rrc variable with an is_match variable. Values other than "match" and "no match" are now handled differently. This allows us to remove the code to check for those cases in various rules. (match): All the case statements use a macro BEGIN_OPCODE instead. And all the continue statements, or break statements that break out of the outer case use a macro NEXT_OPCODE instead. Replaced a few if statements with assertions. (jsRegExpExecute): Use new/delete instead of pcre_malloc/free. Removed unused start_match field from the match block.
  • pcre/pcre_internal.h: Moved the last few configuration macros from pcre-config.h in here. Removed various unused types. Converted from JSRegExpChar to UChar. Eliminated pcre_malloc/free. Replaced the opcode enum with a macro that can be used in multiple places. Unfortunately we lose the comments for each opcode; we should find a place to put those back. Removed ctype_digit.
  • pcre/pcre_maketables.cpp: Copied from JavaScriptCore/pcre/pcre_maketables.c. (pcre_maketables): Got rid of the conditional code that allows this to be compiled in -- it's only used for dftables now (and soon may be obsolete entirely). Changed code for cbit_digit to not use isdigit, and took the "_" case out of the loop. Removed ctype_digit.
  • pcre/pcre_ord2utf8.cpp: Copied from JavaScriptCore/pcre/pcre_ord2utf8.c.
  • pcre/pcre_tables.cpp: Copied from JavaScriptCore/pcre/pcre_tables.c. Moved _pcre_OP_lengths out of here into pcre_exec.cpp.
  • pcre/pcre_ucp_searchfuncs.cpp: Copied from JavaScriptCore/pcre/pcre_ucp_searchfuncs.c. Updated for other file name changes.
  • pcre/ucpinternal.h: Updated header.
  • wtf/ASCIICType.h: (WTF::isASCIIDigit): Removed a branch by changing from && to & for this operation. Also added an overload that takes an int because that's useful for PCRE. Later we could optimize for int and overload other functions in this file; stuck to this simple one for now.
  • wtf/unicode/icu/UnicodeIcu.h: Removed unused isUpper.
  • wtf/unicode/qt4/UnicodeQt4.h: Ditto.
  • pcre/LICENCE: Removed.
  • pcre/pcre-config.h: Removed.
  • wtf/FastMallocPCRE.cpp: Removed.
  • pcre/dftables.c: Renamed to cpp.
  • pcre/pcre_compile.c: Ditto.
  • pcre/pcre_exec.c: Ditto.
  • pcre/pcre_maketables.c: Ditto.
  • pcre/pcre_ord2utf8.c: Ditto.
  • pcre/pcre_tables.c: Ditto.
  • pcre/pcre_ucp_searchfuncs.c: Ditto.
  • pcre/pcre_xclass.c: Ditto.
  • pcre/ucptable.c: Ditto.

WebCore:

Reviewed by Sam.

  • updated for JSRegExp function changes
  • platform/RegularExpression.cpp: (WebCore::RegularExpression::Private::compile): (WebCore::RegularExpression::match):
  • Property svn:eol-style set to native
File size: 2.2 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_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; }
53
54 bool isValid() const { return !m_constructionError; }
55 const char* errorMessage() const { return m_constructionError; }
56
57 int match(const UString&, int offset, OwnArrayPtr<int>* ovector = 0);
58 unsigned numSubpatterns() const { return m_numSubpatterns; }
59
60 private:
61 void compile();
62
63 int m_refCount;
64
65 // Data supplied by caller.
66 UString m_pattern;
67 int m_flags;
68
69 // Data supplied by PCRE.
70 JSRegExp* m_regExp;
71 const char* m_constructionError;
72 unsigned m_numSubpatterns;
73 };
74
75} // namespace
76
77#endif
Note: See TracBrowser for help on using the repository browser.