Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(299)

Unified Diff: runtime/lib/regexp_patch.dart

Issue 539153002: Port and integrate the irregexp engine from V8 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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";
}

Powered by Google App Engine
This is Rietveld 408576698