Index: runtime/lib/regexp_patch.dart |
diff --git a/runtime/lib/regexp_patch.dart b/runtime/lib/regexp_patch.dart |
index 7c9438131082e89df4f2d056c7ca79e62c10e3f6..a9b2649b9f39794844b70dbc07797fd793e261db 100644 |
--- a/runtime/lib/regexp_patch.dart |
+++ b/runtime/lib/regexp_patch.dart |
@@ -5,10 +5,35 @@ |
patch class RegExp { |
/* patch */ factory RegExp(String source, |
{bool multiLine: false, |
- bool caseSensitive: true}) { |
- return new _JSSyntaxRegExp(source, |
+ bool caseSensitive: true}) { |
+ _JSSyntaxRegExpHash hash = new _JSSyntaxRegExpHash( |
+ source, multiLine, caseSensitive); |
+ if (!_regExpCache.containsKey(hash)) { |
+ _regExpCache[hash] = new _JSSyntaxRegExp(source, |
multiLine: multiLine, |
caseSensitive: caseSensitive); |
+ } |
+ |
+ return _regExpCache[hash]; |
+ } |
+ |
+ static final Map<_JSSyntaxRegExpHash, _JSSyntaxRegExp> _regExpCache = |
+ <_JSSyntaxRegExpHash, _JSSyntaxRegExp>{ }; |
+} |
+ |
+// Represents a key in the regular expression cache. |
+class _JSSyntaxRegExpHash { |
+ final String pattern; |
+ final bool multiLine; |
+ final bool caseSensitive; |
+ |
+ _JSSyntaxRegExpHash(this.pattern, this.multiLine, this.caseSensitive); |
+ |
+ int get hashCode => pattern.hashCode; |
+ bool operator==(_JSSyntaxRegExpHash that) { |
+ return (pattern == that.pattern) && |
+ (this.multiLine == that.multiLine) && |
+ (this.caseSensitive == that.caseSensitive); |
} |
} |
@@ -118,6 +143,51 @@ class _JSSyntaxRegExp implements RegExp { |
int get _groupCount native "JSSyntaxRegExp_getGroupCount"; |
+ // Byte map of one byte characters with a 0xff if the character is a word |
+ // character (digit, letter or underscore) and 0x00 otherwise. |
+ // Used by generated RegExp code. |
+ static const List<int> _wordCharacterMap = const <int>[ |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // '0' - '7' |
+ 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // '8' - '9' |
+ |
+ 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'A' - 'G' |
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'H' - 'O' |
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'P' - 'W' |
+ 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0xff, // 'X' - 'Z', '_' |
+ |
+ 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'a' - 'g' |
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'h' - 'o' |
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // 'p' - 'w' |
+ 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, // 'x' - 'z' |
+ // Latin-1 range |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
+ ]; |
+ |
List _ExecuteMatch(String str, int start_index) |
native "JSSyntaxRegExp_ExecuteMatch"; |
} |