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

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

Issue 209443005: Add optimized _OneByteString.toLowerCase. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fix test. 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 | « runtime/lib/string_patch.dart ('k') | tests/corelib/string_to_lower_case_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_parser.dart
diff --git a/sdk/lib/io/http_parser.dart b/sdk/lib/io/http_parser.dart
index 2888138174a0c1b0fd665256d6202b2d1ea9987c..258bfc63e89af294485d570800497ecc3ab4a242 100644
--- a/sdk/lib/io/http_parser.dart
+++ b/sdk/lib/io/http_parser.dart
@@ -547,7 +547,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
_state = _State.HEADER_ENDING;
} else {
// Start of new header field.
- _headerField.add(_toLowerCase(byte));
+ _headerField.add(_toLowerCaseByte(byte));
_state = _State.HEADER_FIELD;
}
break;
@@ -559,7 +559,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
if (!_isTokenChar(byte)) {
throw new HttpException("Invalid header field name");
}
- _headerField.add(_toLowerCase(byte));
+ _headerField.add(_toLowerCaseByte(byte));
}
break;
@@ -615,7 +615,7 @@ class _HttpParser extends Stream<_HttpIncoming> {
_state = _State.HEADER_ENDING;
} else {
// Start of new header field.
- _headerField.add(_toLowerCase(byte));
+ _headerField.add(_toLowerCaseByte(byte));
_state = _State.HEADER_FIELD;
}
}
@@ -933,18 +933,20 @@ class _HttpParser extends Stream<_HttpIncoming> {
return tokens;
}
- int _toLowerCase(int byte) {
- final int aCode = "A".codeUnitAt(0);
- final int zCode = "Z".codeUnitAt(0);
- final int delta = "a".codeUnitAt(0) - aCode;
- return (aCode <= byte && byte <= zCode) ? byte + delta : byte;
+ static int _toLowerCaseByte(int x) {
+ // Optimized version:
+ // - 0x41 is 'A'
+ // - 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;
}
// expected should already be lowercase.
bool _caseInsensitiveCompare(List<int> expected, List<int> value) {
if (expected.length != value.length) return false;
for (int i = 0; i < expected.length; i++) {
- if (expected[i] != _toLowerCase(value[i])) return false;
+ if (expected[i] != _toLowerCaseByte(value[i])) return false;
}
return true;
}
« no previous file with comments | « runtime/lib/string_patch.dart ('k') | tests/corelib/string_to_lower_case_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698