| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
| 6 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/dart_entry.h" | 8 #include "vm/dart_entry.h" |
| 9 #include "vm/exceptions.h" | 9 #include "vm/exceptions.h" |
| 10 #include "vm/native_entry.h" | 10 #include "vm/native_entry.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 if (FLAG_trace_intrinsified_natives) { | 176 if (FLAG_trace_intrinsified_natives) { |
| 177 OS::Print("Integer_equalToInteger %s == %s\n", | 177 OS::Print("Integer_equalToInteger %s == %s\n", |
| 178 left.ToCString(), right.ToCString()); | 178 left.ToCString(), right.ToCString()); |
| 179 } | 179 } |
| 180 return Bool::Get(left.CompareWith(right) == 0); | 180 return Bool::Get(left.CompareWith(right) == 0); |
| 181 } | 181 } |
| 182 | 182 |
| 183 | 183 |
| 184 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { | 184 DEFINE_NATIVE_ENTRY(Integer_parse, 1) { |
| 185 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); | 185 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
| 186 if (value.IsOneByteString()) { |
| 187 // Quick conversion for unpadded integers in strings. |
| 188 const intptr_t len = value.Length(); |
| 189 if (len > 0) { |
| 190 const char* cstr = value.ToCString(); |
| 191 ASSERT(cstr != NULL); |
| 192 // Dart differences from strtol: |
| 193 // a) '+5' is not a valid integer (leading plus). |
| 194 if (cstr[0] != '+') { |
| 195 char* p_end = NULL; |
| 196 const int64_t int_value = strtol(cstr, &p_end, 10); |
| 197 if (p_end == (cstr + len)) { |
| 198 if ((Smi::kMinValue <= int_value) && (int_value <= Smi::kMaxValue)) { |
| 199 return Smi::New(int_value); |
| 200 } |
| 201 } |
| 202 } |
| 203 } |
| 204 } |
| 205 |
| 186 Scanner scanner(value, Symbols::Empty()); | 206 Scanner scanner(value, Symbols::Empty()); |
| 187 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 207 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
| 188 String* int_string; | 208 String* int_string; |
| 189 bool is_positive; | 209 bool is_positive; |
| 190 if (Scanner::IsValidLiteral(tokens, | 210 if (Scanner::IsValidLiteral(tokens, |
| 191 Token::kINTEGER, | 211 Token::kINTEGER, |
| 192 &is_positive, | 212 &is_positive, |
| 193 &int_string)) { | 213 &int_string)) { |
| 194 if (is_positive) { | 214 if (is_positive) { |
| 195 return Integer::New(*int_string); | 215 return Integer::New(*int_string); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 | 324 |
| 305 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { | 325 DEFINE_NATIVE_ENTRY(Bigint_bitNegate, 1) { |
| 306 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); | 326 const Bigint& value = Bigint::CheckedHandle(arguments->NativeArgAt(0)); |
| 307 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); | 327 const Bigint& result = Bigint::Handle(BigintOperations::BitNot(value)); |
| 308 ASSERT(CheckInteger(value)); | 328 ASSERT(CheckInteger(value)); |
| 309 ASSERT(CheckInteger(result)); | 329 ASSERT(CheckInteger(result)); |
| 310 return result.AsValidInteger(); | 330 return result.AsValidInteger(); |
| 311 } | 331 } |
| 312 | 332 |
| 313 } // namespace dart | 333 } // namespace dart |
| OLD | NEW |