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

Side by Side Diff: runtime/lib/integers_patch.dart

Issue 12330149: Dart VM compiler cannot optimize methods with try/catch yet, factor the code out -> 30% gain on a J… (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 patch class int { 8 patch class int {
9 static int _parse(String str) native "Integer_parse"; 9 static int _parse(String str) native "Integer_parse";
10 10
11 static int _throwFormatException(String source) { 11 static int _throwFormatException(String source) {
12 throw new FormatException(source); 12 throw new FormatException(source);
13 } 13 }
14 14
15 /* patch */ static int parse(String source, 15 /* patch */ static int parse(String source,
16 { int radix, 16 { int radix,
17 int onError(String str) }) { 17 int onError(String str) }) {
18 if ((radix == null) && (onError == null)) return _parse(source);
19 return _slowParse(source, radix, onError);
20 }
21
22 static int _slowParse(String source, int radix, int onError(String str)) {
18 if (source is! String) throw new ArgumentError(source); 23 if (source is! String) throw new ArgumentError(source);
19 if (radix == null) { 24 if (radix == null) {
20 if (onError == null) return _parse(source); 25 assert(onError != null);
21 try { 26 try {
22 return _parse(source); 27 return _parse(source);
23 } on FormatException { 28 } on FormatException {
24 return onError(source); 29 return onError(source);
25 } 30 }
26 } 31 }
27 if (radix is! int) throw new ArgumentError("Radix is not an integer"); 32 if (radix is! int) throw new ArgumentError("Radix is not an integer");
28 if (radix < 2 || radix > 36) { 33 if (radix < 2 || radix > 36) {
29 throw new RangeError("Radix $radix not in range 2..36"); 34 throw new RangeError("Radix $radix not in range 2..36");
30 } 35 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 int digit = digits[code - 0x30]; 67 int digit = digits[code - 0x30];
63 if (digit >= radix) return onError(source); 68 if (digit >= radix) return onError(source);
64 result = result * radix + digit; 69 result = result * radix + digit;
65 i++; 70 i++;
66 if (i == source.length) break; 71 if (i == source.length) break;
67 code = source.codeUnitAt(i); 72 code = source.codeUnitAt(i);
68 } while (true); 73 } while (true);
69 return negative ? -result : result; 74 return negative ? -result : result;
70 } 75 }
71 } 76 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698