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

Unified Diff: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart

Issue 11368138: Add some support for the code-point code-unit distinction. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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: sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
diff --git a/sdk/lib/_internal/compiler/implementation/lib/interceptors.dart b/sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
index 2fc25a6fb80f706916b405d3a7fa2ea9a99b107f..b488693453b12b583c7aae1a4a63b054099d448d 100644
--- a/sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
+++ b/sdk/lib/_internal/compiler/implementation/lib/interceptors.dart
@@ -90,13 +90,28 @@ iterator(receiver) {
return UNINTERCEPTED(receiver.iterator());
}
-charCodeAt(var receiver, int index) {
+codeUnitAt(var receiver, int index) {
if (receiver is String) {
if (index is !num) throw new ArgumentError(index);
if (index < 0) throw new RangeError.value(index);
if (index >= receiver.length) throw new RangeError.value(index);
return JS('int', r'#.charCodeAt(#)', receiver, index);
} else {
+ return UNINTERCEPTED(receiver.codeUnitAt(index));
+ }
+}
+
+charCodeAt(var receiver, int index) {
+ if (receiver is String) {
+ if (index is !num) throw new ArgumentError(index);
+ if (index < 0) throw new RangeError.value(index);
+ if (index >= receiver.length) throw new RangeError.value(index);
+ int codeUnit = JS('int', r'#.charCodeAt(#)', receiver, index);
+ if (codeUnit < 0xd800 || codeUnit >= 0xe000) return codeUnit;
+ if (index + 1 == receiver.length) return codeUnit;
+ int codeUnit2 = JS('int', r'#.charCodeAt(#)', receiver, index + 1);
+ return 0x10000 + ((codeUnit & 0x3ff) << 10) + (codeUnit2 & 0x3ff);
+ } else {
return UNINTERCEPTED(receiver.charCodeAt(index));
}
}
@@ -646,12 +661,24 @@ get$hashCode(receiver) {
return 0x1fffffff & (hash + JS('int', r'# << #', 0x00003fff & hash, 15));
}
+get$codeUnits(receiver) {
+ if (receiver is !String) return UNINTERCEPTED(receiver.codeUnits);
+ int len = receiver.length;
+ List<int> result = new List<int>(len);
+ for (int i = 0; i < len; i++) {
+ result[i] = JS('int', r'#.charCodeAt(#)', receiver, i);
floitsch 2012/11/08 15:28:21 why not result[i] = receiver.codeUnitAt(i); ?
erikcorry 2012/11/15 13:28:25 Unfortunately the optimizer can't optimize that aw
+ }
+ return result;
+}
+
get$charCodes(receiver) {
if (receiver is !String) return UNINTERCEPTED(receiver.charCodes);
int len = receiver.length;
List<int> result = new List<int>(len);
- for (int i = 0; i < len; i++) {
- result[i] = receiver.charCodeAt(i);
+ for (int i = 0, j = 0; i < len; i++, j++) {
+ int code = receiver.charCodeAt(i);
+ if (code >= 0x10000) i++;
+ result[j] = code;
}
return result;
}

Powered by Google App Engine
This is Rietveld 408576698