use_is_even_rather_than_modulo (#68301)
This commit is contained in:
committed by
GitHub
parent
3393566b56
commit
c0176c9ee5
@@ -111,7 +111,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
|
||||
key: const Key('complex-scroll'), // this key is used by the driver test
|
||||
controller: ScrollController(), // So that the scroll offset can be tracked
|
||||
itemBuilder: (BuildContext context, int index) {
|
||||
if (index % 2 == 0)
|
||||
if (index.isEven)
|
||||
return FancyImageItem(index, key: PageStorageKey<int>(index));
|
||||
else
|
||||
return FancyGalleryItem(index, key: PageStorageKey<int>(index));
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -21,7 +21,7 @@ void main() {
|
||||
data.add(
|
||||
InlineSpanSemanticsInformation(words[i], isPlaceholder: false),
|
||||
);
|
||||
} else if (i % 2 == 0) {
|
||||
} else if (i.isEven) {
|
||||
data.add(
|
||||
InlineSpanSemanticsInformation(words[i], isPlaceholder: true),
|
||||
);
|
||||
|
||||
@@ -46,7 +46,7 @@ Future<void> main() async {
|
||||
|
||||
watch.start();
|
||||
while (watch.elapsed < kBenchmarkTime) {
|
||||
renderView.configuration = (iterations % 2 == 0) ? big : small;
|
||||
renderView.configuration = iterations.isEven ? big : small;
|
||||
await tester.pumpBenchmark(Duration(milliseconds: iterations * 16));
|
||||
iterations += 1;
|
||||
}
|
||||
|
||||
@@ -1376,7 +1376,7 @@ class ReportedDurationTest {
|
||||
class ListStatistics {
|
||||
factory ListStatistics(Iterable<int> data) {
|
||||
assert(data.isNotEmpty);
|
||||
assert(data.length % 2 == 1);
|
||||
assert(data.length.isOdd);
|
||||
final List<int> sortedData = data.toList()..sort();
|
||||
return ListStatistics._(
|
||||
sortedData.first,
|
||||
|
||||
@@ -28,7 +28,7 @@ class AsymmetricView extends StatelessWidget {
|
||||
return List<Container>.generate(_listItemCount(products.length), (int index) {
|
||||
double width = .59 * MediaQuery.of(context).size.width;
|
||||
Widget column;
|
||||
if (index % 2 == 0) {
|
||||
if (index.isEven) {
|
||||
/// Even cases
|
||||
final int bottom = _evenCasesIndex(index);
|
||||
column = TwoProductCardColumn(
|
||||
|
||||
Reference in New Issue
Block a user