mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
ac73b8e198
Rationale: Improves the analysis if instance calls need checks (check class or check null) combined with CHA. History: revert^2 of original https://dart-review.googlesource.com/c/sdk/+/65220 https://dart-review.googlesource.com/c/sdk/+/64440 Bug: https://github.com/dart-lang/sdk/issues/33664 Change-Id: I21ea857b68ba136d2bd4c9714ab557401ae7c7b8 Reviewed-on: https://dart-review.googlesource.com/66023 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Aart Bik <ajcbik@google.com>
66 lines
1.2 KiB
Dart
66 lines
1.2 KiB
Dart
// Copyright (c) 2018, 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.
|
|
|
|
import "package:expect/expect.dart";
|
|
|
|
// Class hierarchy on an abstract class
|
|
// that defines a "next" structure.
|
|
|
|
abstract class A {
|
|
A next;
|
|
}
|
|
|
|
class B extends A {
|
|
B(A n) {
|
|
this.next = n;
|
|
}
|
|
}
|
|
|
|
// Method that counts length of list.
|
|
// With only Bs, the getter can be
|
|
// inlined without check class.
|
|
int countMe(A i) {
|
|
int x = 0;
|
|
while (i != null) {
|
|
A next = i.next;
|
|
x++;
|
|
i = next;
|
|
}
|
|
return x;
|
|
}
|
|
|
|
int doitHot(A a) {
|
|
// Warm up the JIT.
|
|
int d = 0;
|
|
for (int i = 0; i < 1000; i++) {
|
|
d += countMe(a);
|
|
}
|
|
return d;
|
|
}
|
|
|
|
// Nasty class that overrides the getter.
|
|
class C extends A {
|
|
C(A n) {
|
|
this.next = n;
|
|
}
|
|
// New override.
|
|
A get next => null;
|
|
}
|
|
|
|
int bringInC(A a) {
|
|
// Introduce C to compiler.
|
|
a = new C(a);
|
|
return doitHot(a);
|
|
}
|
|
|
|
main() {
|
|
// Make a list with just Bs.
|
|
A a = null;
|
|
for (int i = 0; i < 1000; i++) {
|
|
a = new B(a);
|
|
}
|
|
|
|
Expect.equals(1000 * 1000, doitHot(a));
|
|
Expect.equals(1000, bringInC(a));
|
|
}
|