Skip to content

Commit 73181a3

Browse files
committed
optimize code
1 parent 14df02d commit 73181a3

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed

lib/src/core.dart

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,28 +2930,18 @@ class _ConstraintRenderBox extends RenderBox
29302930
list.add(node.parentData._constrainedNodeMap[id]!.getBottom());
29312931
}
29322932
}
2933-
double min = double.maxFinite;
2934-
double max = double.minPositive;
2935-
for (final element in list) {
2936-
if (element > max) {
2937-
max = element;
2938-
}
2939-
if (element < min) {
2940-
min = element;
2941-
}
2942-
}
29432933
if (direction == BarrierDirection.left) {
2944-
offsetX = min;
2934+
offsetX = getMinDouble(list);
29452935
offsetY = 0;
29462936
} else if (direction == BarrierDirection.top) {
29472937
offsetX = 0;
2948-
offsetY = min;
2938+
offsetY = getMinDouble(list);
29492939
} else if (direction == BarrierDirection.right) {
2950-
offsetX = max;
2940+
offsetX = getMaxDouble(list);
29512941
offsetY = 0;
29522942
} else {
29532943
offsetX = 0;
2954-
offsetY = max;
2944+
offsetY = getMaxDouble(list);
29552945
}
29562946
} else {
29572947
/// Calculate child x offset
@@ -3581,7 +3571,7 @@ class ConstrainedNode {
35813571
parentData._constrainedNodeMap[id]!
35823572
.getDepth(parentSizeConfirmed, resolvedWidth, resolvedHeight)
35833573
];
3584-
depth = getMax(list) + 1;
3574+
depth = getMaxInt(list) + 1;
35853575
} else {
35863576
List<int> list = [
35873577
if (leftConstraint != null)
@@ -3607,7 +3597,7 @@ class ConstrainedNode {
36073597
getDepthFor(
36083598
element, parentSizeConfirmed, resolvedWidth, resolvedHeight),
36093599
];
3610-
depth = getMax(list) + 1;
3600+
depth = getMaxInt(list) + 1;
36113601
}
36123602
}
36133603
return depth;

lib/src/utils.dart

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ void debugShowPerformance(
478478
context.canvas.drawParagraph(paragraph, Offset(0, heightOffset) + offset);
479479
}
480480

481-
int getMax(List<int> list) {
482-
int max = -1;
481+
int getMaxInt(List<int> list) {
482+
int max = 1 << 63;
483483
for (final element in list) {
484484
if (element > max) {
485485
max = element;
@@ -488,6 +488,26 @@ int getMax(List<int> list) {
488488
return max;
489489
}
490490

491+
double getMaxDouble(List<double> list) {
492+
double max = double.minPositive;
493+
for (final element in list) {
494+
if (element > max) {
495+
max = element;
496+
}
497+
}
498+
return max;
499+
}
500+
501+
double getMinDouble(List<double> list) {
502+
double min = double.maxFinite;
503+
for (final element in list) {
504+
if (element < min) {
505+
min = element;
506+
}
507+
}
508+
return min;
509+
}
510+
491511
/// For debug message print
492512
Map<String, dynamic> toJson(ConstrainedNode node) {
493513
final map = <String, dynamic>{};

0 commit comments

Comments
 (0)