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

Unified Diff: runtime/lib/string_patch.dart

Issue 683433003: Integrate the Irregexp Regular Expression Engine. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: rebase Created 6 years, 2 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/string_patch.dart
diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
index 3a1fd711b6cd06e4a46f44ad383d6258a8d47a76..a65a6bc26257ffe2311814041b4893e739f348cc 100644
--- a/runtime/lib/string_patch.dart
+++ b/runtime/lib/string_patch.dart
@@ -739,6 +739,27 @@ class _OneByteString extends _StringBase implements String {
return super.split(pattern);
}
+ // The codeUnitsAt family of functions is inlined to an unchecked
+ // LoadCodeUnitsInstr, therefore `this` must be a valid string, and `index`
+ // must be in bounds.
+ int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1);
+ int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2);
+ int _fourCodeUnitsAt(int index) => _codeUnitsAt(index, 4);
+
+ // Loads up to 4 code units into a single integer.
+ int _codeUnitsAt(int index, int count) {
+ assert(index >= 0);
+ assert(index + count - 1 < this.length);
+ assert(0 < count && count <= 4);
+
+ int codeUnits = 0;
+ for (int i = 0; i < count; i++) {
+ codeUnits |= this.codeUnitAt(index + i) << (i * 8);
Ivan Posva 2014/10/31 07:32:37 This looks pretty endian specific to me. No?
zerny-google 2014/10/31 11:54:26 Well spotted. The irregexp code works despite this
+ }
+
+ return codeUnits;
+ }
+
// All element of 'strings' must be OneByteStrings.
static _concatAll(List<String> strings, int totalLength) {
// TODO(srdjan): Improve code below and raise or eliminate the limit.
@@ -1003,6 +1024,23 @@ class _TwoByteString extends _StringBase implements String {
bool operator ==(Object other) {
return super == other;
}
+
+ int _oneCodeUnitAt(int index) => _codeUnitsAt(index, 1);
+ int _twoCodeUnitsAt(int index) => _codeUnitsAt(index, 2);
+
+ // Loads up to 2 code units into a single integer.
+ int _codeUnitsAt(int index, int count) {
+ assert(index >= 0);
+ assert(index + count - 1 < this.length);
+ assert(0 < count && count <= 2);
+
+ int codeUnits = 0;
+ for (int i = 0; i < count; i++) {
+ codeUnits |= this.codeUnitAt(index + i) << (i * 16);
Ivan Posva 2014/10/31 07:32:37 ditto.
+ }
+
+ return codeUnits;
+ }
}

Powered by Google App Engine
This is Rietveld 408576698