73b7d0c40a
This is a reland of commite2d6cb69fbOriginal change's description: > Reland "[vm/compiler] Optimize switch statements" > > This is a reland of commitf5228127f8> > Original change's description: > > [vm/compiler] Optimize switch statements > > > > Switch statements that either contain only integers or only enum values of the same type can be optimized. > > > > Depending on the number of switch expressions and the number of holes that the range of switch expressions contains, either a binary search or a jump table is used. > > > > TEST=runtime/test/vm/dart{,_2}/optimized_switch > > TEST=tests/language{,_2}/switch > > > > Fixes: https://github.com/dart-lang/sdk/issues/49585 > > > > Co-authored-by: Gabriel Terwesten gabriel@terwesten.net > > > > Change-Id: I62dcdb7843107f03de7e468c60b4db52ec78f676 > > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253787 > > Reviewed-by: Alexander Markov <alexmarkov@google.com> > > Commit-Queue: Alexander Markov <alexmarkov@google.com> > > TEST=runtime/test/vm/dart{,_2}/optimized_switch > TEST=tests/language{,_2}/switch > > Change-Id: Ie96e5ff41dce33e2425ba9ad15ecd931d09bec6e > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/255700 > Reviewed-by: Alexander Markov <alexmarkov@google.com> > Commit-Queue: Alexander Markov <alexmarkov@google.com> TEST=runtime/test/vm/dart{,_2}/optimized_switch TEST=tests/language{,_2}/switch Change-Id: I56f8d25a88bb856115550c5da3f02c80c7547802 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256180 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Alexander Markov <alexmarkov@google.com>
42 lines
899 B
Dart
42 lines
899 B
Dart
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
// Regression test for issue 18869: Check that try-catch is working correctly
|
|
// inside switch-case clauses.
|
|
|
|
// VMOptions=
|
|
// VMOptions=--force-switch-dispatch-type=0
|
|
// VMOptions=--force-switch-dispatch-type=1
|
|
// VMOptions=--force-switch-dispatch-type=2
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
test_switch() {
|
|
switch (0) {
|
|
_0:
|
|
case 0:
|
|
print("_0");
|
|
continue _5;
|
|
_1:
|
|
case 1:
|
|
try {
|
|
print("bunny");
|
|
continue _6;
|
|
} catch (e) {}
|
|
break;
|
|
_5:
|
|
case 5:
|
|
print("_5");
|
|
continue _6;
|
|
_6:
|
|
case 6:
|
|
print("_6");
|
|
throw 555;
|
|
}
|
|
}
|
|
|
|
main() {
|
|
Expect.throws(() => test_switch(), (e) => e == 555);
|
|
}
|