| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014, 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 // VMOptions=--optimization-counter-threshold=5 |
| 5 // Test correct OSR (issue 16151). |
| 6 |
| 7 import "dart:collection"; |
| 8 import "package:expect/expect.dart"; |
| 9 |
| 10 List create([int length]) { |
| 11 return new MyList(length); |
| 12 } |
| 13 |
| 14 main() { |
| 15 test(create); |
| 16 } |
| 17 |
| 18 |
| 19 class MyList<E> extends ListBase<E> { |
| 20 List<E> _list; |
| 21 |
| 22 MyList([int length]): _list = (length==null ? new List() : new List(length)); |
| 23 |
| 24 E operator [](int index) => _list[index]; |
| 25 |
| 26 void operator []=(int index, E value) { |
| 27 _list[index]=value; |
| 28 } |
| 29 |
| 30 int get length => _list.length; |
| 31 |
| 32 void set length(int newLength) { |
| 33 _list.length=newLength; |
| 34 } |
| 35 } |
| 36 |
| 37 |
| 38 test(List create([int length])) { |
| 39 sort_A01_t02_test(create); |
| 40 } |
| 41 |
| 42 // From library co19 sort_A01_t02. |
| 43 |
| 44 sort_A01_t02_test(List create([int length])) { |
| 45 int c(var a, var b) { |
| 46 return a < b ? -1 : (a == b ? 0 : 1); |
| 47 } |
| 48 |
| 49 int maxlen = 7; |
| 50 int prevLength = 0; |
| 51 for (int length = 1; length < maxlen; ++length) { |
| 52 // Check that we are making progress. |
| 53 if (prevLength == length) { |
| 54 // Cannot use Expect.notEquals since it hides the bug. |
| 55 throw "No progress made"; |
| 56 } |
| 57 prevLength = length; |
| 58 List a = create(length); |
| 59 List expected = create(length); |
| 60 for(int i = 0; i < length; ++i) { |
| 61 expected[i] = i; |
| 62 a[i] = i; |
| 63 } |
| 64 |
| 65 void swap(int i, int j) { |
| 66 var t = a[i]; |
| 67 a[i] = a[j]; |
| 68 a[j] = t; |
| 69 } |
| 70 |
| 71 void check() { |
| 72 return; |
| 73 // Deleting the code below will throw a RangeError instead of throw above. |
| 74 var a_copy = new List(length); |
| 75 a_copy.setRange(0, length, a); |
| 76 a_copy.sort(c); |
| 77 } |
| 78 |
| 79 void permute(int n) { |
| 80 if (n == 1) { |
| 81 check(); |
| 82 } |
| 83 else { |
| 84 for (int i = 0; i < n; i++) { |
| 85 permute(n-1); |
| 86 if (n % 2 == 1) { |
| 87 swap(0, n-1); |
| 88 } else { |
| 89 swap(i, n-1); |
| 90 } |
| 91 } |
| 92 } |
| 93 } //void permute |
| 94 permute(length); |
| 95 } //for i in 0..length |
| 96 } // test |
| OLD | NEW |