use_is_even_rather_than_modulo (#68301)

This commit is contained in:
Alexandre Ardhuin
2020-10-16 20:20:00 +02:00
committed by GitHub
parent 3393566b56
commit c0176c9ee5
22 changed files with 30 additions and 30 deletions

View File

@@ -70,7 +70,7 @@ class _MultiWidgetConstructTableState extends State<MultiWidgetConstructTable>
// This implementation rebuild the widget tree for every
// frame, and is intentionally designed of poor performance
// for benchmark purposes.
return counter % 2 == 0
return counter.isEven
? Container(
// This key forces rebuilding the element
key: ValueKey<int>(widgetCounter + label),

View File

@@ -132,7 +132,7 @@ class ListItem extends StatelessWidget {
),
),
Image.asset(
index % 2 == 0 ? 'food/butternut_squash_soup.png' : 'food/cherry_pie.png',
index.isEven ? 'food/butternut_squash_soup.png' : 'food/cherry_pie.png',
package: 'flutter_gallery_assets',
fit: BoxFit.cover,
width: 110,

View File

@@ -69,7 +69,7 @@ class BenchUpdateManyChildLayers extends SceneBuilderRecorder {
final double offsetY = row * cellSize.height;
// Retain every other layer, so we exercise the update path 50% of the
// time and the retain path the other 50%.
final bool shouldRetain = oldLayer != null && (row + col) % 2 == 0;
final bool shouldRetain = oldLayer != null && (row + col).isEven;
if (shouldRetain) {
sceneBuilder.addRetained(oldLayer);
} else {