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

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: Also use the native parse directly in JSON parsing. 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.cc
diff --git a/runtime/lib/double.cc b/runtime/lib/double.cc
index 83b23d2fcc829d79c804e9e681c1ca7aebfdb396..79fb9fd6c08bbe9b74200a29c283b7885d67edcd 100644
--- a/runtime/lib/double.cc
+++ b/runtime/lib/double.cc
@@ -182,26 +182,25 @@ 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();
+ // Indices should be inside the string, and 0 <= start < end <= len.
// The native function only accepts one-byte strings. The Dart side converts
Vyacheslav Egorov (Google) 2014/07/01 11:36:18 This comment does not seem to be valid anymore.
Lasse Reichstein Nielsen 2014/07/01 11:54:18 Well spotted.
// 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();
+ 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();
}

Powered by Google App Engine
This is Rietveld 408576698