Chromium Code Reviews| Index: runtime/lib/integers.cc |
| =================================================================== |
| --- runtime/lib/integers.cc (revision 18930) |
| +++ runtime/lib/integers.cc (working copy) |
| @@ -183,6 +183,26 @@ |
| DEFINE_NATIVE_ENTRY(Integer_parse, 1) { |
| GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
| + if (value.IsOneByteString()) { |
| + // Quick conversion for unpadded integers in strings. |
| + const intptr_t len = value.Length(); |
| + if (len > 0) { |
| + const char* cstr = value.ToCString(); |
| + ASSERT(cstr != NULL); |
| + // Dart differences from strtol: |
| + // a) '+5' is not a valid integer (leading plus). |
| + if (cstr[0] != '+') { |
| + char* p_end = NULL; |
| + const int64_t int_value = strtol(cstr, &p_end, 10); |
| + if (p_end == (cstr + len)) { |
|
siva
2013/02/25 06:22:44
Should this be if (cstr + strlen(cstr)) because if
srdjan
2013/02/25 18:02:44
strlen is slow and we cannot have a valid double w
|
| + if ((Smi::kMinValue <= int_value) && (int_value <= Smi::kMaxValue)) { |
| + return Smi::New(int_value); |
| + } |
| + } |
| + } |
| + } |
| + } |
| + |
| Scanner scanner(value, Symbols::Empty()); |
| const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
| String* int_string; |