Files
sdk/pkg/compiler/test/inlining/data/conditional.dart
T
Joshua Litt 20faaa5d94 [dart2js] Move dart2js unit tests to pkg/compiler/test.
Change-Id: Ib18f554c1076f27a3f7c0df5a36410da41a1f467
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148784
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
2020-05-28 18:51:11 +00:00

63 lines
1.8 KiB
Dart

// Copyright (c) 2017, 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.
// @dart = 2.7
// Tests for the heuristics on conditional expression whose condition is a
// parameter for which the max, instead of the sum, of the branch sizes is used.
/*member: main:[]*/
main() {
conditionalField();
conditionalParameter();
}
////////////////////////////////////////////////////////////////////////////////
// Conditional expression on a non-parameter (here a top-level field). The
// size of the condition is the sum of the nodes in the conditional expression.
////////////////////////////////////////////////////////////////////////////////
/*member: _method1:[_conditionalField]*/
_method1() => 42;
bool _field1;
/*member: _conditionalField:[]*/
_conditionalField() {
return _field1
? _method1() + _method1() + _method1()
: _method1() + _method1() + _method1();
}
/*member: conditionalField:[]*/
@pragma('dart2js:noInline')
conditionalField() {
_field1 = false;
_conditionalField();
_field1 = true;
_conditionalField();
}
////////////////////////////////////////////////////////////////////////////////
// Conditional expression on a parameter. The size of the condition is the
// max of the branches + the condition itself.
////////////////////////////////////////////////////////////////////////////////
/*member: _method2:[conditionalParameter]*/
_method2() => 42;
/*member: _conditionalParameter:[conditionalParameter]*/
_conditionalParameter(bool o) {
return o
? _method2() + _method2() + _method2()
: _method2() + _method2() + _method2();
}
/*member: conditionalParameter:[]*/
@pragma('dart2js:noInline')
conditionalParameter() {
_conditionalParameter(true);
_conditionalParameter(false);
}