| 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 // Dart core library. | 4 // Dart core library. |
| 5 | 5 |
| 6 // VM implementation of int. | 6 // VM implementation of int. |
| 7 | 7 |
| 8 import 'dart:_internal' as internal; | 8 import 'dart:_internal' as internal; |
| 9 | 9 |
| 10 @patch class int { | 10 @patch class int { |
| 11 | 11 |
| 12 /* @patch */ const factory int.fromEnvironment(String name, | 12 @patch const factory int.fromEnvironment(String name, |
| 13 {int defaultValue}) | 13 {int defaultValue}) |
| 14 native "Integer_fromEnvironment"; | 14 native "Integer_fromEnvironment"; |
| 15 | 15 |
| 16 | 16 |
| 17 static int _tryParseSmi(String str, int first, int last) { | 17 static int _tryParseSmi(String str, int first, int last) { |
| 18 assert(first <= last); | 18 assert(first <= last); |
| 19 var ix = first; | 19 var ix = first; |
| 20 var sign = 1; | 20 var sign = 1; |
| 21 var c = str.codeUnitAt(ix); | 21 var c = str.codeUnitAt(ix); |
| 22 // Check for leading '+' or '-'. | 22 // Check for leading '+' or '-'. |
| 23 if ((c == 0x2b) || (c == 0x2d)) { | 23 if ((c == 0x2b) || (c == 0x2d)) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 for (int i = ix; i <= last; i++) { | 35 for (int i = ix; i <= last; i++) { |
| 36 var c = 0x30 ^ str.codeUnitAt(i); | 36 var c = 0x30 ^ str.codeUnitAt(i); |
| 37 if (9 < c) { | 37 if (9 < c) { |
| 38 return null; | 38 return null; |
| 39 } | 39 } |
| 40 result = 10 * result + c; | 40 result = 10 * result + c; |
| 41 } | 41 } |
| 42 return sign * result; | 42 return sign * result; |
| 43 } | 43 } |
| 44 | 44 |
| 45 /* @patch */ static int parse(String source, | 45 @patch static int parse(String source, |
| 46 { int radix, | 46 { int radix, |
| 47 int onError(String str) }) { | 47 int onError(String str) }) { |
| 48 if (source == null) throw new ArgumentError("The source must not be null"); | 48 if (source == null) throw new ArgumentError("The source must not be null"); |
| 49 if (source.isEmpty) return _throwFormatException(onError, source, 0, radix); | 49 if (source.isEmpty) return _throwFormatException(onError, source, 0, radix); |
| 50 if (radix == null || radix == 10) { | 50 if (radix == null || radix == 10) { |
| 51 // Try parsing immediately, without trimming whitespace. | 51 // Try parsing immediately, without trimming whitespace. |
| 52 int result = _tryParseSmi(source, 0, source.length - 1); | 52 int result = _tryParseSmi(source, 0, source.length - 1); |
| 53 if (result != null) return result; | 53 if (result != null) return result; |
| 54 } else if (radix < 2 || radix > 36) { | 54 } else if (radix < 2 || radix > 36) { |
| 55 throw new RangeError("Radix $radix not in range 2..36"); | 55 throw new RangeError("Radix $radix not in range 2..36"); |
| 56 } | 56 } |
| 57 // Split here so improve odds of parse being inlined and the checks omitted. | 57 // Split here so improve odds of parse being inlined and the checks omitted. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 6, 594823321, 12, 353814783205469041, | 204 6, 594823321, 12, 353814783205469041, |
| 205 6, 729000000, 12, 531441000000000000, /* radix: 30 */ | 205 6, 729000000, 12, 531441000000000000, /* radix: 30 */ |
| 206 6, 887503681, 12, 787662783788549761, | 206 6, 887503681, 12, 787662783788549761, |
| 207 6, 1073741824, 12, 1152921504606846976, | 207 6, 1073741824, 12, 1152921504606846976, |
| 208 5, 39135393, 12, 1667889514952984961, | 208 5, 39135393, 12, 1667889514952984961, |
| 209 5, 45435424, 12, 2386420683693101056, | 209 5, 45435424, 12, 2386420683693101056, |
| 210 5, 52521875, 12, 3379220508056640625, /* radix: 35 */ | 210 5, 52521875, 12, 3379220508056640625, /* radix: 35 */ |
| 211 5, 60466176, 11, 131621703842267136, | 211 5, 60466176, 11, 131621703842267136, |
| 212 ]; | 212 ]; |
| 213 } | 213 } |
| OLD | NEW |