Skip to content

Commit 1bfba75

Browse files
authored
Added identical(a,b) short circuit to rendering library lerp methods (#121566)
Added identical(a,b) short circuit to rendering library lerp methods
1 parent c4ef072 commit 1bfba75

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

packages/flutter/lib/src/rendering/box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ class BoxConstraints extends Constraints {
468468
///
469469
/// {@macro dart.ui.shadow.lerp}
470470
static BoxConstraints? lerp(BoxConstraints? a, BoxConstraints? b, double t) {
471-
if (a == null && b == null) {
472-
return null;
471+
if (identical(a, b)) {
472+
return a;
473473
}
474474
if (a == null) {
475475
return b! * t;

packages/flutter/lib/src/rendering/stack.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class RelativeRect {
165165
///
166166
/// {@macro dart.ui.shadow.lerp}
167167
static RelativeRect? lerp(RelativeRect? a, RelativeRect? b, double t) {
168-
if (a == null && b == null) {
169-
return null;
168+
if (identical(a, b)) {
169+
return a;
170170
}
171171
if (a == null) {
172172
return RelativeRect.fromLTRB(b!.left * t, b.top * t, b.right * t, b.bottom * t);

packages/flutter/lib/src/rendering/table_border.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ class TableBorder {
153153
///
154154
/// {@macro dart.ui.shadow.lerp}
155155
static TableBorder? lerp(TableBorder? a, TableBorder? b, double t) {
156-
if (a == null && b == null) {
157-
return null;
156+
if (identical(a, b)) {
157+
return a;
158158
}
159159
if (a == null) {
160160
return b!.scale(t);

packages/flutter/test/rendering/box_constraints_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ void main() {
9090
expect(copy.maxHeight, moreOrLessEquals(97.0));
9191
});
9292

93+
test('BoxConstraints.lerp identical a,b', () {
94+
expect(BoxConstraints.lerp(null, null, 0), null);
95+
const BoxConstraints constraints = BoxConstraints();
96+
expect(identical(BoxConstraints.lerp(constraints, constraints, 0.5), constraints), true);
97+
});
98+
9399
test('BoxConstraints lerp with unbounded width', () {
94100
const BoxConstraints constraints1 = BoxConstraints(
95101
minWidth: double.infinity,

packages/flutter/test/rendering/relative_rect_test.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ void main() {
6767
final RelativeRect r3 = RelativeRect.lerp(r1, r2, 0.5)!;
6868
expect(r3, const RelativeRect.fromLTRB(5.0, 10.0, 15.0, 20.0));
6969
});
70+
test('RelativeRect.lerp identical a,b', () {
71+
expect(RelativeRect.lerp(null, null, 0), null);
72+
const RelativeRect rect = RelativeRect.fill;
73+
expect(identical(RelativeRect.lerp(rect, rect, 0.5), rect), true);
74+
});
7075
}

packages/flutter/test/rendering/table_border_test.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ void main() {
108108
);
109109
});
110110

111+
test('TableBorder.lerp identical a,b', () {
112+
expect(TableBorder.lerp(null, null, 0), null);
113+
const TableBorder border = TableBorder();
114+
expect(identical(TableBorder.lerp(border, border, 0.5), border), true);
115+
});
116+
111117
test('TableBorder.lerp with nulls', () {
112118
final TableBorder table2 = TableBorder.all(width: 2.0);
113119
final TableBorder table1 = TableBorder.all();

0 commit comments

Comments
 (0)