source: webkit/trunk/JavaScriptCore/runtime/RegExp.h@ 50254

Last change on this file since 50254 was 45545, checked in by [email protected], 16 years ago

2009-07-03 Yong Li <[email protected]>

Reviewed by Maciej Stachowiak (and revised slightly)

RegExp::match to be optimized
https://bugs.webkit.org/show_bug.cgi?id=26957

Allow regexp matching to use Vectors with inline capacity instead of
allocating a new ovector buffer every time.


~5% speedup on SunSpider string-unpack-code test, 0.3% on SunSpider overall.

  • runtime/RegExp.cpp: (JSC::RegExp::match):
  • runtime/RegExp.h:
  • runtime/RegExpConstructor.cpp: (JSC::RegExpConstructorPrivate::RegExpConstructorPrivate): (JSC::RegExpConstructorPrivate::lastOvector): (JSC::RegExpConstructorPrivate::tempOvector): (JSC::RegExpConstructorPrivate::changeLastOvector): (JSC::RegExpConstructor::performMatch): (JSC::RegExpMatchesArray::RegExpMatchesArray): (JSC::RegExpMatchesArray::fillArrayInstance): (JSC::RegExpConstructor::getBackref): (JSC::RegExpConstructor::getLastParen): (JSC::RegExpConstructor::getLeftContext): (JSC::RegExpConstructor::getRightContext):
  • runtime/StringPrototype.cpp: (JSC::stringProtoFuncSplit):
  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2007, 2008, 2009 Apple Inc. All rights reserved.
4 * Copyright (C) 2009 Torch Mobile, Inc.
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 RegExp_h
23#define RegExp_h
24
25#include "UString.h"
26#include "WREC.h"
27#include "ExecutableAllocator.h"
28#include <wtf/Forward.h>
29#include <wtf/RefCounted.h>
30#include "yarr/RegexJIT.h"
31#include "yarr/RegexInterpreter.h"
32
33struct JSRegExp;
34
35namespace JSC {
36
37 class JSGlobalData;
38
39 class RegExp : public RefCounted<RegExp> {
40 public:
41 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern);
42 static PassRefPtr<RegExp> create(JSGlobalData* globalData, const UString& pattern, const UString& flags);
43#if !ENABLE(YARR)
44 ~RegExp();
45#endif
46
47 bool global() const { return m_flagBits & Global; }
48 bool ignoreCase() const { return m_flagBits & IgnoreCase; }
49 bool multiline() const { return m_flagBits & Multiline; }
50
51 const UString& pattern() const { return m_pattern; }
52 const UString& flags() const { return m_flags; }
53
54 bool isValid() const { return !m_constructionError; }
55 const char* errorMessage() const { return m_constructionError; }
56
57 int match(const UString&, int startOffset, Vector<int, 32>* ovector = 0);
58 unsigned numSubpatterns() const { return m_numSubpatterns; }
59
60 private:
61 RegExp(JSGlobalData* globalData, const UString& pattern);
62 RegExp(JSGlobalData* globalData, const UString& pattern, const UString& flags);
63
64 void compile(JSGlobalData*);
65
66 enum FlagBits { Global = 1, IgnoreCase = 2, Multiline = 4 };
67
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 const char* m_constructionError;
72 unsigned m_numSubpatterns;
73
74#if ENABLE(YARR_JIT)
75 Yarr::RegexCodeBlock m_regExpJITCode;
76#elif ENABLE(YARR)
77 OwnPtr<Yarr::BytecodePattern> m_regExpBytecode;
78#else
79#if ENABLE(WREC)
80 WREC::CompiledRegExp m_wrecFunction;
81 RefPtr<ExecutablePool> m_executablePool;
82#endif
83 JSRegExp* m_regExp;
84#endif
85 };
86
87} // namespace JSC
88
89#endif // RegExp_h
Note: See TracBrowser for help on using the repository browser.