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

Unified Diff: runtime/lib/string_patch.dart

Issue 209443005: Add optimized _OneByteString.toLowerCase. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Move impl to _OneByteString. 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_parser.dart » ('j') | sdk/lib/io/http_parser.dart » ('J')
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 667a08772516cf18f3c5b8f8886ceddcd538fa33..db194f440b21cd3ee65abc190d221c15ed00d453 100644
--- a/runtime/lib/string_patch.dart
+++ b/runtime/lib/string_patch.dart
@@ -778,6 +778,56 @@ class _OneByteString extends _StringBase implements String {
return result;
}
+ int _nextLowerCase(int offset) {
Søren Gjesse 2014/03/25 15:28:05 Shouldn't this be called _nextUpperCase/_nextUpper
+ final length = this.length;
+ while (offset < length) {
+ int codeUnit = this.codeUnitAt(offset);
srdjan 2014/03/25 15:46:31 final codeUnit
+ if (((codeUnit - 0x41) & 0xff) < 26) {
+ // Optimzed ASCII check:
srdjan 2014/03/25 15:46:31 s/Optimzed/Optimized/
+ // - 0x41 is 'A'
+ // - 0xff is LATIN1 mask
+ // - 26 is the number of characters in this range.
+ return offset;
+ } else if ((((codeUnit - 0xc0) & 0xff) < 32) && codeUnit != 0xd7) {
+ // Optimzed remaining LATIN1 check:
srdjan 2014/03/25 15:46:31 ditto
+ // - 0xc0 is first character > 127
+ // - 0xff is LATIN1 mask
+ // - 32 is the number of characters in this range.
+ // - 0xd7 is an exception in the this range.
+ return offset;
+ }
+ offset++;
+ }
+ return -1;
+ }
+
+ String toLowerCase() {
+ int next = _nextLowerCase(0);
+ if (next == -1) return this;
+ final length = this.length;
+ _OneByteString result = _OneByteString._allocate(length);
+ int offset = 0;
+ do {
+ // Copy all up to the next one.
+ while (offset < next) {
+ result._setAt(offset, this.codeUnitAt(offset));
+ offset++;
+ }
+ // 0x20 is the delta between lower and upper, in both ranges. It's
+ // possible to 'or' instead of 'add', due to the layout.
+ result._setAt(offset, this.codeUnitAt(offset) | 0x20);
srdjan 2014/03/25 15:46:31 What is the advantage of using OR instead of ADD?
Anders Johnsen 2014/03/25 19:35:50 No need for SMI overflow checks?
+ offset++;
+ next = _nextLowerCase(offset);
+ } while (next != -1);
+ // Remaining characters.
+ while (offset < length) {
+ result._setAt(offset, this.codeUnitAt(offset));
+ offset++;
+ }
+ return result;
sra1 2014/03/25 16:00:33 In the case of a one character string, the VM migh
Anders Johnsen 2014/03/25 19:35:50 Done.
+
+ }
+
// Allocates a string of given length, expecting its content to be
// set using _setAt.
static _OneByteString _allocate(int length) native "OneByteString_allocate";
« no previous file with comments | « no previous file | sdk/lib/io/http_parser.dart » ('j') | sdk/lib/io/http_parser.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698