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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/io/http_date.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 // Constants used when working with native ports. 7 // Constants used when working with native ports.
8 // These must match the constants in runtime/bin/dartutils.h class CObject. 8 // These must match the constants in runtime/bin/dartutils.h class CObject.
9 const int _SUCCESS_RESPONSE = 0; 9 const int _SUCCESS_RESPONSE = 0;
10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 newBuffer[i] = value; 115 newBuffer[i] = value;
116 j++; 116 j++;
117 } 117 }
118 return new _BufferAndStart(newBuffer, 0); 118 return new _BufferAndStart(newBuffer, 0);
119 } 119 }
120 120
121 121
122 class _IOCrypto { 122 class _IOCrypto {
123 external static Uint8List getRandomBytes(int count); 123 external static Uint8List getRandomBytes(int count);
124 } 124 }
125
126 class _ASCII {
127 static int toLowerCaseByte(int x) {
128 // Optimzed version:
129 // - 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,
130 // - 0x7f is ASCII mask
131 // - 26 is the number of alpha characters.
132 // - 0x20 is the delta between lower and upper chars.
133 return ((x - 0x41) & 0x7f) < 26 ? x | 0x20 : x;
134 }
135
136 static String toLowerCase(String str) {
137 final length = str.length;
138 List result = new Uint8List(length);
139 for (int i = 0; i < length; i++) {
140 int codeUnit = str.codeUnitAt(i);
141 if (codeUnit > 127) {
142 throw new FormatException("ASCII string contains non-ASCII character.");
143 }
144 result[i] = toLowerCaseByte(codeUnit);
145 }
146 return new String.fromCharCodes(result);
147 }
148 }
OLDNEW
« 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