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

Unified Diff: runtime/lib/string_patch.dart

Issue 212163005: Speed up toLowerCase, by manually inlining the upper-case part. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string_patch.dart
diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
index 717e49db71984f56878bbfcf0cde617c7efb3be5..61ea5dcbd8553a76c2c763d16c7d238df7b9c91a 100644
--- a/runtime/lib/string_patch.dart
+++ b/runtime/lib/string_patch.dart
@@ -779,6 +779,8 @@ class _OneByteString extends _StringBase implements String {
}
// Lower-case conversion table for Latin-1.
+ // Upper-case ranges: 0x41-0x5a ('A' - 'Z'), 0xc0-0xd6, 0xd8-0xde.
+ // Conversion to lower case performed by adding 0x20.
static const _LC_TABLE = const [
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -814,28 +816,19 @@ class _OneByteString extends _StringBase implements String {
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
];
- String _toLowerCaseUpperCaseDetectedAt(int firstUpperCaseIndex) {
- // String contains upper case characters. Create a new string.
- final length = this.length;
- final result = _allocate(length);
- // First up to firstUpperIndex.
- int i = 0;
- for (; i < firstUpperCaseIndex; i++) {
- result._setAt(i, this.codeUnitAt(i));
- }
- for (; i < length; i++) {
- result._setAt(i, _LC_TABLE[this.codeUnitAt(i)]);
- }
- return result;
- }
-
String toLowerCase() {
for (int i = 0; i < this.length; i++) {
final c = this.codeUnitAt(i);
- // Ranges: 0x41-0x5a ('A' - 'Z'), 0xc0-0xd6, 0xd8-0xde.
- if (c != _LC_TABLE[c]) {
- return _toLowerCaseUpperCaseDetectedAt(i);
+ if (c == _LC_TABLE[c]) continue;
+ // Upper-case character found.
+ final result = _allocate(this.length);
+ for (int j = 0; j < i; j++) {
+ result._setAt(j, this.codeUnitAt(j));
}
+ for (int j = i; j < this.length; j++) {
+ result._setAt(j, _LC_TABLE[this.codeUnitAt(j)]);
+ }
+ return result;
}
return this;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698