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

Unified Diff: runtime/lib/double.cc

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
« no previous file with comments | « no previous file | runtime/lib/double_patch.dart » ('j') | runtime/lib/string_patch.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/double.cc
diff --git a/runtime/lib/double.cc b/runtime/lib/double.cc
index 83b23d2fcc829d79c804e9e681c1ca7aebfdb396..1a33ec0e502c01eb21127a02bec2f10500b9bc2d 100644
--- a/runtime/lib/double.cc
+++ b/runtime/lib/double.cc
@@ -182,26 +182,23 @@ DEFINE_NATIVE_ENTRY(Double_toInt, 1) {
}
-DEFINE_NATIVE_ENTRY(Double_parse, 1) {
+DEFINE_NATIVE_ENTRY(Double_parse, 3) {
GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
+ GET_NON_NULL_NATIVE_ARGUMENT(Integer, startValue, arguments->NativeArgAt(1));
+ GET_NON_NULL_NATIVE_ARGUMENT(Integer, endValue, arguments->NativeArgAt(2));
+ const intptr_t start = startValue.AsTruncatedUint32Value();
+ const intptr_t end = endValue.AsTruncatedUint32Value();
const intptr_t len = value.Length();
- // The native function only accepts one-byte strings. The Dart side converts
- // other types of strings to one-byte strings, if necessary.
- if ((!value.IsOneByteString() && !value.IsExternalOneByteString())
- || (len == 0)) {
- return Object::null();
- }
-
- double double_value;
- const char* cstr = value.ToCString();
- ASSERT(cstr != NULL);
- if (CStringToDouble(cstr, len, &double_value)) {
- return Double::New(double_value);
- } else {
- return Object::null();
+ // Indices should be inside the string, and 0 <= start < end <= len.
+ if (0 <= start && start < end && end <= len) {
+ double double_value;
+ if (String::ParseDouble(value, start, end, &double_value)) {
+ return Double::New(double_value);
+ }
}
+ return Object::null();
}
« no previous file with comments | « no previous file | runtime/lib/double_patch.dart » ('j') | runtime/lib/string_patch.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698