Unverified Commit 80679f0b authored by Pascal Welsch's avatar Pascal Welsch Committed by GitHub

[flutter_test] perf: find.ancestor (#108868)

parent 7270c48b
......@@ -923,7 +923,8 @@ class _DescendantFinder extends Finder {
@override
Iterable<Element> apply(Iterable<Element> candidates) {
return candidates.where((Element element) => descendant.evaluate().contains(element));
final Iterable<Element> descendants = descendant.evaluate();
return candidates.where((Element element) => descendants.contains(element));
}
@override
......@@ -956,7 +957,8 @@ class _AncestorFinder extends Finder {
@override
Iterable<Element> apply(Iterable<Element> candidates) {
return candidates.where((Element element) => ancestor.evaluate().contains(element));
final Iterable<Element> ancestors = ancestor.evaluate();
return candidates.where((Element element) => ancestors.contains(element));
}
@override
......
......@@ -361,6 +361,30 @@ void main() {
matchRoot: true,
), findsOneWidget);
});
testWidgets('is fast in deep tree', (WidgetTester tester) async {
await tester.pumpWidget(
Directionality(
textDirection: TextDirection.ltr,
child: _deepWidgetTree(
depth: 1000,
child: Row(
children: <Widget>[
_deepWidgetTree(
depth: 1000,
child: Column(children: fooBarTexts),
),
],
),
),
),
);
expect(find.ancestor(
of: find.text('bar'),
matching: find.byType(Row),
), findsOneWidget);
});
});
group('pageBack', () {
......@@ -854,3 +878,12 @@ class _AlwaysRepaint extends CustomPainter {
onPaint();
}
}
/// Wraps [child] in [depth] layers of [SizedBox]
Widget _deepWidgetTree({required int depth, required Widget child}) {
Widget tree = child;
for (int i = 0; i < depth; i += 1) {
tree = SizedBox(child: tree);
}
return tree;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment