Changeset 27702 in webkit for trunk/JavaScriptCore
- Timestamp:
- Nov 11, 2007, 8:27:33 PM (18 years ago)
- Location:
- trunk/JavaScriptCore
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r27698 r27702 1 2007-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 1 28 2007-11-11 Oliver Hunt <[email protected]> 2 29 -
trunk/JavaScriptCore/kjs/nodes.cpp
r27695 r27702 454 454 JSValue* RegExpNode::evaluate(ExecState* exec) 455 455 { 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); 462 457 } 463 458 -
trunk/JavaScriptCore/kjs/nodes.h
r27695 r27702 29 29 #include "Parser.h" 30 30 #include "internal.h" 31 #include "RegExp.h" 31 32 #include "SymbolTable.h" 32 33 #include <wtf/ListRefPtr.h> … … 271 272 public: 272 273 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; 275 278 virtual void streamTo(SourceStream&) const KJS_FAST_CALL; 276 279 virtual Precedence precedence() const { return PrecPrimary; } 277 280 private: 278 UString m_pattern; 279 UString m_flags; 281 RefPtr<RegExp> m_regExp; 280 282 }; 281 283 -
trunk/JavaScriptCore/kjs/nodes2string.cpp
r27695 r27702 291 291 void RegExpNode::streamTo(SourceStream& s) const 292 292 { 293 s << '/' << m_ pattern << '/' << m_flags;293 s << '/' << m_regExp->pattern() << '/' << m_regExp->flags(); 294 294 } 295 295 -
trunk/JavaScriptCore/kjs/regexp.cpp
r27686 r27702 2 2 /* 3 3 * 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. 5 6 * 6 7 * This library is free software; you can redistribute it and/or … … 34 35 : m_refCount(0) 35 36 , m_pattern(pattern) 36 , m_flag s(0)37 , m_flagBits(0) 37 38 , m_constructionError(0) 38 39 , m_numSubpatterns(0) 39 40 { 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(), 41 42 JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, &m_numSubpatterns, &m_constructionError); 42 43 } … … 45 46 : m_refCount(0) 46 47 , m_pattern(pattern) 47 , m_flags(0) 48 , m_flags(flags) 49 , m_flagBits(0) 48 50 , m_constructionError(0) 49 51 , m_numSubpatterns(0) … … 52 54 // String::match and RegExpImp::match. 53 55 if (flags.find('g') != -1) 54 m_flag s |= Global;56 m_flagBits |= Global; 55 57 56 58 // FIXME: Eliminate duplication by adding a way ask a JSRegExp what its flags are? 57 59 JSRegExpIgnoreCaseOption ignoreCaseOption = JSRegExpDoNotIgnoreCase; 58 60 if (flags.find('i') != -1) { 59 m_flag s |= IgnoreCase;61 m_flagBits |= IgnoreCase; 60 62 ignoreCaseOption = JSRegExpIgnoreCase; 61 63 } … … 63 65 JSRegExpMultilineOption multilineOption = JSRegExpSingleLine; 64 66 if (flags.find('m') != -1) { 65 m_flag s |= Multiline;67 m_flagBits |= Multiline; 66 68 multilineOption = JSRegExpMultiline; 67 69 } 68 70 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(), 70 72 ignoreCaseOption, multilineOption, &m_numSubpatterns, &m_constructionError); 71 73 } -
trunk/JavaScriptCore/kjs/regexp.h
r27686 r27702 47 47 int refCount() { return m_refCount; } 48 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; } 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 52 53 const UString& pattern() const { return m_pattern; } 54 const UString& flags() const { return m_flags; } 53 55 54 56 bool isValid() const { return !m_constructionError; } … … 64 66 65 67 // 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; 68 71 69 72 // Data supplied by PCRE. -
trunk/JavaScriptCore/kjs/regexp_object.cpp
r27573 r27702 449 449 UString pattern = arg0->isUndefined() ? UString("") : arg0->toString(exec); 450 450 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 455 JSObject* 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())); 456 460 } 457 461 -
trunk/JavaScriptCore/kjs/regexp_object.h
r27571 r27702 86 86 virtual bool implementsConstruct() const; 87 87 virtual JSObject* construct(ExecState*, const List&); 88 JSObject* createRegExpImp(ExecState*, PassRefPtr<RegExp>); 88 89 virtual JSValue* callAsFunction(ExecState*, JSObject*, const List&); 89 90 virtual void put(ExecState*, const Identifier&, JSValue*, int attributes = None);
Note:
See TracChangeset
for help on using the changeset viewer.