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

Unified Diff: runtime/lib/double.cc

Issue 12317076: Improve performance of String::ToCString for OneByteString and parsing of doubles. Leads to signifi… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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/vm/object.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/double.cc
===================================================================
--- runtime/lib/double.cc (revision 18922)
+++ runtime/lib/double.cc (working copy)
@@ -200,6 +200,36 @@
DEFINE_NATIVE_ENTRY(Double_parse, 1) {
GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0));
+ if (value.IsOneByteString()) {
+ // Quick conversion for unpadded doubles in strings.
+ const intptr_t len = value.Length();
+ if (len > 0) {
+ const char* cstr = value.ToCString();
+ ASSERT(cstr != NULL);
+ // Dart differences from strtod:
+ // a) '5.' is not a valid double (no digit after period).
+ // b) '+5.0' is not a valid double (leading plus).
+ if (cstr[0] != '+') {
+ bool dot_ok = true;
+ const char* tmp = cstr;
+ while (*tmp != '\0') {
+ const char ch = *tmp++;
+ if (ch == '.') {
+ const char nextCh = *tmp;
+ dot_ok = ('0' <= nextCh) && (nextCh <= '9');
+ break;
+ }
+ }
+ if (dot_ok) {
+ char* p_end = NULL;
+ const double double_value = strtod(cstr, &p_end);
+ if (p_end == (cstr + len)) {
+ return Double::New(double_value);
+ }
+ }
+ }
+ }
+ }
Scanner scanner(value, Symbols::Empty());
const Scanner::GrowableTokenStream& tokens = scanner.GetStream();
String* number_string;
« no previous file with comments | « no previous file | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698