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

Unified Diff: sdk/lib/io/common.dart

Issue 209443005: Add optimized _OneByteString.toLowerCase. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Optimize toLowerCase. Created 6 years, 9 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
« no previous file with comments | « no previous file | sdk/lib/io/http_date.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/common.dart
diff --git a/sdk/lib/io/common.dart b/sdk/lib/io/common.dart
index ea355801147789b965aafbea16516674ce4680f8..9d9a81826ec1b706c9ee9ea4d252093f3a9cc263 100644
--- a/sdk/lib/io/common.dart
+++ b/sdk/lib/io/common.dart
@@ -122,3 +122,27 @@ _BufferAndStart _ensureFastAndSerializableByteData(
class _IOCrypto {
external static Uint8List getRandomBytes(int count);
}
+
+class _ASCII {
+ static int toLowerCaseByte(int x) {
+ // Optimzed version:
+ // - 0x41 is 'A'
kevmoo 2014/03/25 14:38:25 LOVE the explicit comments. No guessing. Thanks!
Anders Johnsen 2014/03/25 15:00:22 Yeah, it helps understanding. Moved stuff around,
+ // - 0x7f is ASCII mask
+ // - 26 is the number of alpha characters.
+ // - 0x20 is the delta between lower and upper chars.
+ return ((x - 0x41) & 0x7f) < 26 ? x | 0x20 : x;
+ }
+
+ static String toLowerCase(String str) {
+ final length = str.length;
+ List result = new Uint8List(length);
+ for (int i = 0; i < length; i++) {
+ int codeUnit = str.codeUnitAt(i);
+ if (codeUnit > 127) {
+ throw new FormatException("ASCII string contains non-ASCII character.");
+ }
+ result[i] = toLowerCaseByte(codeUnit);
+ }
+ return new String.fromCharCodes(result);
+ }
+}
« no previous file with comments | « no previous file | sdk/lib/io/http_date.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698