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

Unified Diff: runtime/lib/double_patch.dart

Issue 368483004: Avoid unnecessary copying when parsing doubles. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 6 years, 6 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
Index: runtime/lib/double_patch.dart
diff --git a/runtime/lib/double_patch.dart b/runtime/lib/double_patch.dart
index d0367250dcd2cb082e021cd29d07df65a046c843..a239a7523ce6f0b42fa71856c2c83f934846c017 100644
--- a/runtime/lib/double_patch.dart
+++ b/runtime/lib/double_patch.dart
@@ -7,34 +7,17 @@
patch class double {
- static double _native_parse(_OneByteString string) native "Double_parse";
+ static double _nativeParse(String str,
+ int start, int end) native "Double_parse";
static double _parse(var str) {
- str = str.trim();
+ int len = str.length;
+ int start = str._firstNonWhitespace();
+ if (start == len) return null; // All whitespace.
+ int end = str._lastNonWhitespace() + 1;
+ assert(start < end);
- if (str.length == 0) return null;
-
- final ccid = ClassID.getID(str);
- _OneByteString oneByteString;
- // TODO(Srdjan): Allow _ExternalOneByteStrings.
- if (ccid == ClassID.cidOneByteString) {
- oneByteString = str;
- } else {
- int length = str.length;
- var s = _OneByteString._allocate(length);
- for (int i = 0; i < length; i++) {
- int currentUnit = str.codeUnitAt(i);
- // All valid trimmed double strings must be ASCII.
- if (currentUnit < 128) {
- s._setAt(i, currentUnit);
- } else {
- return null;
- }
- }
- oneByteString = s;
- }
-
- return _native_parse(oneByteString);
+ return _nativeParse(str, start, end);
}
/* patch */ static double parse(String str,

Powered by Google App Engine
This is Rietveld 408576698