Skip to content

Commit 1c75363

Browse files
authored
Added identical(a,b) short circuit to painting Library lerp methods (#121346)
1 parent 07b0252 commit 1c75363

30 files changed

+268
-59
lines changed

packages/flutter/lib/src/painting/alignment.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ abstract class AlignmentGeometry {
8787
///
8888
/// {@macro dart.ui.shadow.lerp}
8989
static AlignmentGeometry? lerp(AlignmentGeometry? a, AlignmentGeometry? b, double t) {
90-
if (a == null && b == null) {
91-
return null;
90+
if (identical(a, b)) {
91+
return a;
9292
}
9393
if (a == null) {
9494
return b! * t;
@@ -337,8 +337,8 @@ class Alignment extends AlignmentGeometry {
337337
///
338338
/// {@macro dart.ui.shadow.lerp}
339339
static Alignment? lerp(Alignment? a, Alignment? b, double t) {
340-
if (a == null && b == null) {
341-
return null;
340+
if (identical(a, b)) {
341+
return a;
342342
}
343343
if (a == null) {
344344
return Alignment(ui.lerpDouble(0.0, b!.x, t)!, ui.lerpDouble(0.0, b.y, t)!);
@@ -528,8 +528,8 @@ class AlignmentDirectional extends AlignmentGeometry {
528528
///
529529
/// {@macro dart.ui.shadow.lerp}
530530
static AlignmentDirectional? lerp(AlignmentDirectional? a, AlignmentDirectional? b, double t) {
531-
if (a == null && b == null) {
532-
return null;
531+
if (identical(a, b)) {
532+
return a;
533533
}
534534
if (a == null) {
535535
return AlignmentDirectional(ui.lerpDouble(0.0, b!.start, t)!, ui.lerpDouble(0.0, b.y, t)!);

packages/flutter/lib/src/painting/border_radius.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ abstract class BorderRadiusGeometry {
129129
///
130130
/// {@macro dart.ui.shadow.lerp}
131131
static BorderRadiusGeometry? lerp(BorderRadiusGeometry? a, BorderRadiusGeometry? b, double t) {
132-
if (a == null && b == null) {
133-
return null;
132+
if (identical(a, b)) {
133+
return a;
134134
}
135135
a ??= BorderRadius.zero;
136136
b ??= BorderRadius.zero;
@@ -506,8 +506,8 @@ class BorderRadius extends BorderRadiusGeometry {
506506
///
507507
/// {@macro dart.ui.shadow.lerp}
508508
static BorderRadius? lerp(BorderRadius? a, BorderRadius? b, double t) {
509-
if (a == null && b == null) {
510-
return null;
509+
if (identical(a, b)) {
510+
return a;
511511
}
512512
if (a == null) {
513513
return b! * t;
@@ -727,8 +727,8 @@ class BorderRadiusDirectional extends BorderRadiusGeometry {
727727
///
728728
/// {@macro dart.ui.shadow.lerp}
729729
static BorderRadiusDirectional? lerp(BorderRadiusDirectional? a, BorderRadiusDirectional? b, double t) {
730-
if (a == null && b == null) {
731-
return null;
730+
if (identical(a, b)) {
731+
return a;
732732
}
733733
if (a == null) {
734734
return b! * t;

packages/flutter/lib/src/painting/borders.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ class BorderSide with Diagnosticable {
260260
///
261261
/// {@macro dart.ui.shadow.lerp}
262262
static BorderSide lerp(BorderSide a, BorderSide b, double t) {
263+
if (identical(a, b)) {
264+
return a;
265+
}
263266
if (t == 0.0) {
264267
return a;
265268
}
@@ -519,6 +522,9 @@ abstract class ShapeBorder {
519522
///
520523
/// {@macro dart.ui.shadow.lerp}
521524
static ShapeBorder? lerp(ShapeBorder? a, ShapeBorder? b, double t) {
525+
if (identical(a, b)) {
526+
return a;
527+
}
522528
ShapeBorder? result;
523529
if (b != null) {
524530
result = b.lerpFrom(a, t);
@@ -708,6 +714,9 @@ abstract class OutlinedBorder extends ShapeBorder {
708714
///
709715
/// {@macro dart.ui.shadow.lerp}
710716
static OutlinedBorder? lerp(OutlinedBorder? a, OutlinedBorder? b, double t) {
717+
if (identical(a, b)) {
718+
return a;
719+
}
711720
ShapeBorder? result;
712721
if (b != null) {
713722
result = b.lerpFrom(a, t);

packages/flutter/lib/src/painting/box_border.dart

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ abstract class BoxBorder extends ShapeBorder {
103103
///
104104
/// {@macro dart.ui.shadow.lerp}
105105
static BoxBorder? lerp(BoxBorder? a, BoxBorder? b, double t) {
106+
if (identical(a, b)) {
107+
return a;
108+
}
106109
if ((a is Border?) && (b is Border?)) {
107110
return Border.lerp(a, b, t);
108111
}
@@ -469,8 +472,8 @@ class Border extends BoxBorder {
469472
///
470473
/// {@macro dart.ui.shadow.lerp}
471474
static Border? lerp(Border? a, Border? b, double t) {
472-
if (a == null && b == null) {
473-
return null;
475+
if (identical(a, b)) {
476+
return a;
474477
}
475478
if (a == null) {
476479
return b!.scale(t);
@@ -811,8 +814,8 @@ class BorderDirectional extends BoxBorder {
811814
///
812815
/// {@macro dart.ui.shadow.lerp}
813816
static BorderDirectional? lerp(BorderDirectional? a, BorderDirectional? b, double t) {
814-
if (a == null && b == null) {
815-
return null;
817+
if (identical(a, b)) {
818+
return a;
816819
}
817820
if (a == null) {
818821
return b!.scale(t);

packages/flutter/lib/src/painting/box_decoration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,8 @@ class BoxDecoration extends Decoration {
288288
/// and which use [BoxDecoration.lerp] when interpolating two
289289
/// [BoxDecoration]s or a [BoxDecoration] to or from null.
290290
static BoxDecoration? lerp(BoxDecoration? a, BoxDecoration? b, double t) {
291-
if (a == null && b == null) {
292-
return null;
291+
if (identical(a, b)) {
292+
return a;
293293
}
294294
if (a == null) {
295295
return b!.scale(t);

packages/flutter/lib/src/painting/box_shadow.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ class BoxShadow extends ui.Shadow {
8686
///
8787
/// {@macro dart.ui.shadow.lerp}
8888
static BoxShadow? lerp(BoxShadow? a, BoxShadow? b, double t) {
89-
if (a == null && b == null) {
90-
return null;
89+
if (identical(a, b)) {
90+
return a;
9191
}
9292
if (a == null) {
9393
return b!.scale(t);
@@ -110,8 +110,8 @@ class BoxShadow extends ui.Shadow {
110110
///
111111
/// {@macro dart.ui.shadow.lerp}
112112
static List<BoxShadow>? lerpList(List<BoxShadow>? a, List<BoxShadow>? b, double t) {
113-
if (a == null && b == null) {
114-
return null;
113+
if (identical(a, b)) {
114+
return a;
115115
}
116116
a ??= <BoxShadow>[];
117117
b ??= <BoxShadow>[];

packages/flutter/lib/src/painting/colors.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ class HSVColor {
194194
///
195195
/// Values outside of the valid range for each channel will be clamped.
196196
static HSVColor? lerp(HSVColor? a, HSVColor? b, double t) {
197-
if (a == null && b == null) {
198-
return null;
197+
if (identical(a, b)) {
198+
return a;
199199
}
200200
if (a == null) {
201201
return b!._scaleAlpha(t);
@@ -377,8 +377,8 @@ class HSLColor {
377377
/// Values for `t` are usually obtained from an [Animation<double>], such as
378378
/// an [AnimationController].
379379
static HSLColor? lerp(HSLColor? a, HSLColor? b, double t) {
380-
if (a == null && b == null) {
381-
return null;
380+
if (identical(a, b)) {
381+
return a;
382382
}
383383
if (a == null) {
384384
return b!._scaleAlpha(t);
@@ -479,13 +479,12 @@ class ColorSwatch<T> extends Color {
479479
/// Values for `t` are usually obtained from an [Animation<double>], such as
480480
/// an [AnimationController].
481481
static ColorSwatch<T>? lerp<T>(ColorSwatch<T>? a, ColorSwatch<T>? b, double t) {
482+
if (identical(a, b)) {
483+
return a;
484+
}
482485
final Map<T, Color> swatch;
483486
if (b == null) {
484-
if (a == null) {
485-
return null;
486-
} else {
487-
swatch = a._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(color, null, t)!));
488-
}
487+
swatch = a!._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(color, null, t)!));
489488
} else {
490489
if (a == null) {
491490
swatch = b._swatch.map((T key, Color color) => MapEntry<T, Color>(key, Color.lerp(null, color, t)!));

packages/flutter/lib/src/painting/decoration.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ abstract class Decoration with Diagnosticable {
129129
///
130130
/// {@macro dart.ui.shadow.lerp}
131131
static Decoration? lerp(Decoration? a, Decoration? b, double t) {
132-
if (a == null && b == null) {
133-
return null;
132+
if (identical(a, b)) {
133+
return a;
134134
}
135135
if (a == null) {
136136
return b!.lerpFrom(null, t) ?? b;

packages/flutter/lib/src/painting/edge_insets.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ abstract class EdgeInsetsGeometry {
215215
///
216216
/// {@macro dart.ui.shadow.lerp}
217217
static EdgeInsetsGeometry? lerp(EdgeInsetsGeometry? a, EdgeInsetsGeometry? b, double t) {
218-
if (a == null && b == null) {
219-
return null;
218+
if (identical(a, b)) {
219+
return a;
220220
}
221221
if (a == null) {
222222
return b! * t;
@@ -611,8 +611,8 @@ class EdgeInsets extends EdgeInsetsGeometry {
611611
///
612612
/// {@macro dart.ui.shadow.lerp}
613613
static EdgeInsets? lerp(EdgeInsets? a, EdgeInsets? b, double t) {
614-
if (a == null && b == null) {
615-
return null;
614+
if (identical(a, b)) {
615+
return a;
616616
}
617617
if (a == null) {
618618
return b! * t;
@@ -877,8 +877,8 @@ class EdgeInsetsDirectional extends EdgeInsetsGeometry {
877877
///
878878
/// {@macro dart.ui.shadow.lerp}
879879
static EdgeInsetsDirectional? lerp(EdgeInsetsDirectional? a, EdgeInsetsDirectional? b, double t) {
880-
if (a == null && b == null) {
881-
return null;
880+
if (identical(a, b)) {
881+
return a;
882882
}
883883
if (a == null) {
884884
return b! * t;

packages/flutter/lib/src/painting/flutter_logo.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ class FlutterLogoDecoration extends Decoration {
101101
static FlutterLogoDecoration? lerp(FlutterLogoDecoration? a, FlutterLogoDecoration? b, double t) {
102102
assert(a == null || a.debugAssertIsValid());
103103
assert(b == null || b.debugAssertIsValid());
104-
if (a == null && b == null) {
105-
return null;
104+
if (identical(a, b)) {
105+
return a;
106106
}
107107
if (a == null) {
108108
return FlutterLogoDecoration._(

0 commit comments

Comments
 (0)