Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
c0176c9e
Unverified
Commit
c0176c9e
authored
Oct 16, 2020
by
Alexandre Ardhuin
Committed by
GitHub
Oct 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use_is_even_rather_than_modulo (#68301)
parent
3393566b
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
30 additions
and
30 deletions
+30
-30
analysis_options.yaml
analysis_options.yaml
+1
-1
main.dart
dev/benchmarks/complex_layout/lib/main.dart
+1
-1
multi_widget_construction.dart
...ks/macrobenchmarks/lib/src/multi_widget_construction.dart
+1
-1
picture_cache.dart
dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart
+1
-1
bench_child_layers.dart
...marks/macrobenchmarks/lib/src/web/bench_child_layers.dart
+1
-1
sync_star_semantics_bench.dart
...crobenchmarks/lib/language/sync_star_semantics_bench.dart
+1
-1
layout_bench.dart
dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart
+1
-1
perf_tests.dart
dev/devicelab/lib/tasks/perf_tests.dart
+1
-1
asymmetric_view.dart
...gallery/lib/demo/shrine/supplemental/asymmetric_view.dart
+1
-1
animation_controller.dart
packages/flutter/lib/src/animation/animation_controller.dart
+1
-1
mergeable_material.dart
packages/flutter/lib/src/material/mergeable_material.dart
+1
-1
rotated_box.dart
packages/flutter/lib/src/rendering/rotated_box.dart
+1
-1
caching_iterable_test.dart
packages/flutter/test/foundation/caching_iterable_test.dart
+1
-1
automatic_keep_alive_test.dart
packages/flutter/test/widgets/automatic_keep_alive_test.dart
+1
-1
list_view_viewporting_test.dart
...ages/flutter/test/widgets/list_view_viewporting_test.dart
+1
-1
page_view_test.dart
packages/flutter/test/widgets/page_view_test.dart
+5
-5
scrollable_dispose_test.dart
packages/flutter/test/widgets/scrollable_dispose_test.dart
+1
-1
semantics_keep_alive_offstage_test.dart
...tter/test/widgets/semantics_keep_alive_offstage_test.dart
+1
-1
slivers_appbar_floating_pinned_test.dart
...ter/test/widgets/slivers_appbar_floating_pinned_test.dart
+1
-1
slivers_test.dart
packages/flutter/test/widgets/slivers_test.dart
+2
-2
transformed_scrollable_test.dart
...ges/flutter/test/widgets/transformed_scrollable_test.dart
+4
-4
event_simulation_test.dart
packages/flutter_test/test/event_simulation_test.dart
+1
-1
No files found.
analysis_options.yaml
View file @
c0176c9e
...
...
@@ -216,7 +216,7 @@ linter:
# - unsafe_html # not yet tested
-
use_full_hex_values_for_flutter_colors
# - use_function_type_syntax_for_parameters # not yet tested
# - use_is_even_rather_than_modulo # not yet tested
-
use_is_even_rather_than_modulo
# - use_key_in_widget_constructors # not yet tested
-
use_late_for_private_fields_and_variables
# - use_raw_strings # not yet tested
...
...
dev/benchmarks/complex_layout/lib/main.dart
View file @
c0176c9e
...
...
@@ -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
));
...
...
dev/benchmarks/macrobenchmarks/lib/src/multi_widget_construction.dart
View file @
c0176c9e
...
...
@@ -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
),
...
...
dev/benchmarks/macrobenchmarks/lib/src/picture_cache.dart
View file @
c0176c9e
...
...
@@ -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
,
...
...
dev/benchmarks/macrobenchmarks/lib/src/web/bench_child_layers.dart
View file @
c0176c9e
...
...
@@ -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
{
...
...
dev/benchmarks/microbenchmarks/lib/language/sync_star_semantics_bench.dart
View file @
c0176c9e
...
...
@@ -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
),
);
...
...
dev/benchmarks/microbenchmarks/lib/stocks/layout_bench.dart
View file @
c0176c9e
...
...
@@ -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
;
}
...
...
dev/devicelab/lib/tasks/perf_tests.dart
View file @
c0176c9e
...
...
@@ -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
,
...
...
dev/integration_tests/flutter_gallery/lib/demo/shrine/supplemental/asymmetric_view.dart
View file @
c0176c9e
...
...
@@ -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
(
...
...
packages/flutter/lib/src/animation/animation_controller.dart
View file @
c0176c9e
...
...
@@ -864,7 +864,7 @@ class _RepeatingSimulation extends Simulation {
final
double
totalTimeInSeconds
=
timeInSeconds
+
_initialT
;
final
double
t
=
(
totalTimeInSeconds
/
_periodInSeconds
)
%
1.0
;
final
bool
_isPlayingReverse
=
(
totalTimeInSeconds
~/
_periodInSeconds
)
%
2
==
1
;
final
bool
_isPlayingReverse
=
(
totalTimeInSeconds
~/
_periodInSeconds
)
.
isOdd
;
if
(
reverse
&&
_isPlayingReverse
)
{
directionSetter
(
_AnimationDirection
.
reverse
);
...
...
packages/flutter/lib/src/material/mergeable_material.dart
View file @
c0176c9e
...
...
@@ -711,7 +711,7 @@ class _RenderMergeableMaterialListBody extends RenderListBody {
while
(
child
!=
null
)
{
final
ListBodyParentData
childParentData
=
child
.
parentData
!
as
ListBodyParentData
;
final
Rect
rect
=
(
childParentData
.
offset
+
offset
)
&
child
.
size
;
if
(
i
%
2
==
0
)
if
(
i
.
isEven
)
_paintShadows
(
context
.
canvas
,
rect
);
child
=
childParentData
.
nextSibling
;
...
...
packages/flutter/lib/src/rendering/rotated_box.dart
View file @
c0176c9e
...
...
@@ -42,7 +42,7 @@ class RenderRotatedBox extends RenderBox with RenderObjectWithChildMixin<RenderB
markNeedsLayout
();
}
bool
get
_isVertical
=>
quarterTurns
%
2
==
1
;
bool
get
_isVertical
=>
quarterTurns
.
isOdd
;
@override
double
computeMinIntrinsicWidth
(
double
height
)
{
...
...
packages/flutter/test/foundation/caching_iterable_test.dart
View file @
c0176c9e
...
...
@@ -55,7 +55,7 @@ void main() {
final
Iterable
<
int
>
integers
=
CachingIterable
<
int
>(
range
(
1
,
5
).
iterator
);
expect
(
yieldCount
,
equals
(
0
));
final
Iterable
<
int
>
evens
=
integers
.
where
((
int
i
)
=>
i
%
2
==
0
);
final
Iterable
<
int
>
evens
=
integers
.
where
((
int
i
)
=>
i
.
isEven
);
expect
(
yieldCount
,
equals
(
0
));
expect
(
evens
.
first
,
equals
(
2
));
...
...
packages/flutter/test/widgets/automatic_keep_alive_test.dart
View file @
c0176c9e
...
...
@@ -515,7 +515,7 @@ void main() {
addSemanticIndexes:
false
,
itemCount:
250
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
if
(
index
%
2
==
0
)
{
if
(
index
.
isEven
)
{
return
_AlwaysKeepAlive
(
key:
GlobalObjectKey
<
_AlwaysKeepAliveState
>(
index
),
);
...
...
packages/flutter/test/widgets/list_view_viewporting_test.dart
View file @
c0176c9e
...
...
@@ -509,7 +509,7 @@ void main() {
itemBuilder:
(
_
,
int
i
)
=>
Container
(
height:
200.0
,
width:
200.0
,
color:
i
%
2
==
0
?
Colors
.
black
:
Colors
.
red
,
color:
i
.
isEven
?
Colors
.
black
:
Colors
.
red
,
),
),
),
...
...
packages/flutter/test/widgets/page_view_test.dart
View file @
c0176c9e
...
...
@@ -393,7 +393,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
200.0
,
color:
index
%
2
==
0
color:
index
.
isEven
?
const
Color
(
0xFF0000FF
)
:
const
Color
(
0xFF00FF00
),
child:
Text
(
kStates
[
index
]),
...
...
@@ -499,7 +499,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
200.0
,
color:
index
%
2
==
0
color:
index
.
isEven
?
const
Color
(
0xFF0000FF
)
:
const
Color
(
0xFF00FF00
),
child:
Text
(
kStates
[
index
]),
...
...
@@ -543,7 +543,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
200.0
,
color:
index
%
2
==
0
color:
index
.
isEven
?
const
Color
(
0xFF0000FF
)
:
const
Color
(
0xFF00FF00
),
child:
Text
(
kStates
[
index
]),
...
...
@@ -576,7 +576,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
200.0
,
color:
index
%
2
==
0
color:
index
.
isEven
?
const
Color
(
0xFF0000FF
)
:
const
Color
(
0xFF00FF00
),
child:
Text
(
kStates
[
index
]),
...
...
@@ -615,7 +615,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
200.0
,
color:
index
%
2
==
0
color:
index
.
isEven
?
const
Color
(
0xFF0000FF
)
:
const
Color
(
0xFF00FF00
),
child:
Text
(
index
.
toString
()),
...
...
packages/flutter/test/widgets/scrollable_dispose_test.dart
View file @
c0176c9e
...
...
@@ -49,7 +49,7 @@ void main() {
controller:
controller
,
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
color:
index
%
2
==
0
?
Colors
.
red
:
Colors
.
green
,
color:
index
.
isEven
?
Colors
.
red
:
Colors
.
green
,
height:
200.0
,
child:
Text
(
'Hello
$index
'
),
);
...
...
packages/flutter/test/widgets/semantics_keep_alive_offstage_test.dart
View file @
c0176c9e
...
...
@@ -99,7 +99,7 @@ Widget _buildTestWidget({
controller:
controller
,
children:
List
<
Widget
>.
generate
(
10
,
(
int
i
)
{
return
Container
(
color:
i
%
2
==
0
?
Colors
.
red
:
Colors
.
blue
,
color:
i
.
isEven
?
Colors
.
red
:
Colors
.
blue
,
height:
250.0
,
child:
Text
(
'Item
$i
'
),
);
...
...
packages/flutter/test/widgets/slivers_appbar_floating_pinned_test.dart
View file @
c0176c9e
...
...
@@ -72,7 +72,7 @@ void main() {
(
BuildContext
_
,
int
index
)
{
return
Container
(
height:
100.0
,
color:
index
%
2
==
0
?
Colors
.
red
:
Colors
.
yellow
,
color:
index
.
isEven
?
Colors
.
red
:
Colors
.
yellow
,
child:
Text
(
'Tile
$index
'
),
);
},
...
...
packages/flutter/test/widgets/slivers_test.dart
View file @
c0176c9e
...
...
@@ -889,10 +889,10 @@ void main() {
(
BuildContext
context
,
int
index
)
{
return
Container
(
child:
Material
(
color:
index
%
2
==
0
?
Colors
.
yellow
:
Colors
.
red
,
color:
index
.
isEven
?
Colors
.
yellow
:
Colors
.
red
,
child:
InkWell
(
onTap:
()
{
index
%
2
==
0
?
firstTapped
++
:
secondTapped
++;
index
.
isEven
?
firstTapped
++
:
secondTapped
++;
},
child:
Text
(
'Index
$index
'
),
),
...
...
packages/flutter/test/widgets/transformed_scrollable_test.dart
View file @
c0176c9e
...
...
@@ -26,7 +26,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
100.0
,
color:
index
%
2
==
0
?
Colors
.
blue
:
Colors
.
red
,
color:
index
.
isEven
?
Colors
.
blue
:
Colors
.
red
,
child:
Text
(
'Tile
$index
'
),
);
},
...
...
@@ -70,7 +70,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
100.0
,
color:
index
%
2
==
0
?
Colors
.
blue
:
Colors
.
red
,
color:
index
.
isEven
?
Colors
.
blue
:
Colors
.
red
,
child:
Text
(
'Tile
$index
'
),
);
},
...
...
@@ -114,7 +114,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
100.0
,
color:
index
%
2
==
0
?
Colors
.
blue
:
Colors
.
red
,
color:
index
.
isEven
?
Colors
.
blue
:
Colors
.
red
,
child:
Text
(
'Tile
$index
'
),
);
},
...
...
@@ -156,7 +156,7 @@ void main() {
itemBuilder:
(
BuildContext
context
,
int
index
)
{
return
Container
(
height:
100.0
,
color:
index
%
2
==
0
?
Colors
.
blue
:
Colors
.
red
,
color:
index
.
isEven
?
Colors
.
blue
:
Colors
.
red
,
child:
Text
(
'Tile
$index
'
),
);
},
...
...
packages/flutter_test/test/event_simulation_test.dart
View file @
c0176c9e
...
...
@@ -36,7 +36,7 @@ void main() {
expect
(
events
.
length
,
8
);
for
(
int
i
=
0
;
i
<
events
.
length
;
++
i
)
{
final
bool
isEven
=
i
%
2
==
0
;
final
bool
isEven
=
i
.
isEven
;
if
(
isEven
)
{
expect
(
events
[
i
].
runtimeType
,
equals
(
RawKeyDownEvent
));
}
else
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment