Chromium Code Reviews| Index: runtime/lib/double.cc |
| =================================================================== |
| --- runtime/lib/double.cc (revision 18861) |
| +++ runtime/lib/double.cc (working copy) |
| @@ -200,6 +200,35 @@ |
| 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) { |
| + char* p_end = NULL; |
|
siva
2013/02/22 21:47:09
Can this local declaration be moved down under
if
srdjan
2013/02/22 22:27:37
Done.
|
| + const char* cstr = value.ToCString(); |
|
siva
2013/02/22 21:47:09
ASSERT(cstr != NULL);
srdjan
2013/02/22 22:27:37
Done.
|
| + // 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) { |
| + 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; |