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

Side by Side Diff: tests/language/try_catch_optimized1_test.dart

Issue 14682020: Optimize functions containing try-catch. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: rebased Created 7 years, 7 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 | « tests/language/try_catch5_test.dart ('k') | tests/language/try_catch_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 import "package:expect/expect.dart";
6
7 maythrow(x) {
8 if (x == null) throw 42;
9 return 99;
10 }
11
12
13 f1(x) {
14 var result = 123;
15 try {
16 result = maythrow(x);
17 if (result > 100) throw 42;
18 } catch(e) {
19 Expect.equals(result, 123);
20 Expect.equals(42, e);
21 result = 0;
22 }
23 return result;
24 }
25
26
27 class A {
28 maythrow(x) {
29 if (x == null) throw 42;
30 return 99;
31 }
32 }
33
34
35 f2(x) {
36 var result = 123;
37 var a = new A();
38 try {
39 result++;
40 result = a.maythrow(x);
41 } catch(e) {
42 Expect.equals(124, result);
43 result = x;
44 }
45 return result;
46 }
47
48
49 f3(x, y) {
50 var result = 123;
51 var a = new A();
52 try {
53 result++;
54 result = a.maythrow(x);
55 } catch(e) {
56 result = y + 1; // Deopt on overflow
57 }
58 return result;
59 }
60
61
62 f4(x) {
63 try {
64 maythrow(x);
65 } catch(e) {
66 check_f4(e, "abc");
67 }
68 }
69
70 check_f4(e, s) {
71 if (e != 42) throw "ERROR";
72 if (s != "abc") throw "ERROR";
73 }
74
75
76 f5(x) {
77 try {
78 maythrow(x);
79 } catch(e) {
80 check_f5(e, "abc");
81 }
82
83 try {
84 maythrow(x);
85 } catch(e) {
86 check_f5(e, "abc");
87 }
88 }
89
90 check_f5(e, s) {
91 if (e != 42) throw "ERROR";
92 if (s != "abc") throw "ERROR";
93 }
94
95
96 f6(x, y) {
97 var a = x;
98 var b = y;
99 var c = 123;
100 check_f6(42, null, 1, 123, null, 1);
101 try {
102 maythrow(x);
103 } catch(e) {
104 check_f6(e, a, b, c, x, y);
105 }
106 }
107
108 check_f6(e, a, b, c, x, y) {
109 if (e != 42) throw "ERROR";
110 if (a != null) throw "ERROR";
111 if (b != 1) throw "ERROR";
112 if (c != 123) throw "ERROR";
113 if (x != null) throw "ERROR";
114 if (y != 1) throw "ERROR";
115 }
116
117
118 bool f7(String str) {
119 double d = double.parse(str);
120 var t = d;
121 try {
122 var a = d.toInt();
123 return false;
124 } on UnsupportedError catch (e) {
125 Expect.equals(true, identical(t, d));
126 return true;
127 }
128 }
129
130
131 f8(x, [a = 3, b = 4]) {
132 var c = 123;
133 var y = a;
134 try {
135 maythrow(x);
136 } catch(e, s) {
137 check_f8(e, s, a, b, c, x, y);
138 }
139 }
140
141 check_f8(e, s, a, b, c, x, y) {
142 if (e != 42) throw "ERROR";
143 if (s is! StackTrace) throw "ERROR";
144 if (a != 3) { print(a); throw "ERROR"; }
145 if (b != 4) throw "ERROR";
146 if (c != 123) throw "ERROR";
147 if (x != null) throw "ERROR";
148 if (y != a) throw "ERROR";
149 }
150
151
152 f9(x, [a = 3, b = 4]) {
153 var c = 123;
154 var y = a;
155 try {
156 if (x < a) maythrow(null);
157 maythrow(x);
158 } catch(e, s) {
159 check_f9(e, s, a, b, c, x, y);
160 }
161 }
162
163
164 check_f9(e, s, a, b, c, x, y) {
165 if (e != 42) throw "ERROR";
166 if (s is! StackTrace) throw "ERROR";
167 if (a != 3) { print(a); throw "ERROR"; }
168 if (b != 4) throw "ERROR";
169 if (c != 123) throw "ERROR";
170 if (x != null) throw "ERROR";
171 if (y != a) throw "ERROR";
172 }
173
174
175 f10(x, y) {
176 var result = 123;
177 try {
178 result = maythrow(x);
179 } catch(e) {
180 Expect.equals(123, result);
181 Expect.equals(0.5, y / 2.0);
182 result = 0;
183 }
184 return result;
185 }
186
187
188 f11(x) {
189 var result = 123;
190 var tmp = x;
191 try {
192 result = maythrow(x);
193 if (result > 100) throw 42;
194 } catch(e, s) {
195 Expect.equals(123, result);
196 Expect.equals(true, identical(tmp, x));
197 Expect.equals(true, s is StackTrace);
198 result = 0;
199 }
200 return result;
201 }
202
203
204 f12([x = null]) {
205 try {
206 maythrow(x);
207 } catch(e) {
208 check_f12(e, x);
209 }
210 }
211
212 check_f12(e, x) {
213 if (e != 42) throw "ERROR";
214 if (x != null) throw "ERROR";
215 }
216
217
218 f13(x) {
219 var result = 123;
220 try {
221 try {
222 result = maythrow(x);
223 if (result > 100) throw 42;
224 } catch(e) {
225 Expect.equals(123, result);
226 result = 0;
227 }
228 maythrow(x);
229 } catch(e) {
230 result++;
231 }
232 return result;
233 }
234
235
236 main() {
237 for (var i=0; i<10000; i++) f1("abc");
238 Expect.equals(99, f1("abc"));
239 Expect.equals(0, f1(null));
240
241 for (var i=0; i<10000; i++) f2("abc");
242 Expect.equals(99, f2("abc"));
243 Expect.equals(null, f2(null));
244
245 f3("123", 0);
246 for (var i=0; i<10000; i++) f3(null, 0);
247 Expect.equals(99, f3("123", 0));
248 Expect.equals(0x40000000, f3(null, 0x3fffffff));
249
250 f4(null);
251 for (var i=0; i<10000; i++) f4(123);
252 f4(null);
253
254 f5(null);
255 for (var i=0; i<10000; i++) f5(123);
256 f5(null);
257
258 f6(null, 1);
259 for (var i=0; i<10000; i++) f6(123, 1);
260 f6(null, 1);
261
262 f7("1.2");
263 f7("Infinity");
264 f7("-Infinity");
265 for (var i=0; i<10000; i++) f7("1.2");
266 Expect.equals(false, f7("1.2"));
267 Expect.equals(true, f7("Infinity"));
268 Expect.equals(true, f7("-Infinity"));
269 Expect.equals(false, f7("123456789012345")); // Deopt.
270 for (var i=0; i<10000; i++) f7("123456789012345");
271 Expect.equals(true, f7("Infinity"));
272 Expect.equals(true, f7("-Infinity"));
273
274 for (var i=0; i<10000; i++) f8(null);
275 f8(null);
276
277 f9(5);
278 f9(5.0);
279 for (var i=0; i<10000; i++) f9(3);
280 f9(3);
281
282 var y = 1.0;
283 Expect.equals(0, f10(null, y));
284 for (var i = 0; i < 10000; i++) f10("abc", y);
285 Expect.equals(99, f10("abc", y));
286 Expect.equals(0, f10(null, y));
287
288 for (var i=0; i<10000; i++) f11("abc");
289 Expect.equals(99, f11("abc"));
290 Expect.equals(0, f11(null));
291
292 for (var i=0; i<10000; i++) f12(null);
293 f12(null);
294
295 f13(null);
296 for (var i=0; i<10000; i++) f13("abc");
297 Expect.equals(99, f13("abc"));
298 Expect.equals(1, f13(null));
299 }
OLDNEW
« no previous file with comments | « tests/language/try_catch5_test.dart ('k') | tests/language/try_catch_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698