Commit 9157c164 authored by Adam Barth's avatar Adam Barth

The intrinsic size checks were very slow

Now we run them once per render object.

Fixes #2487
parent 992fc76e
...@@ -653,6 +653,9 @@ abstract class RenderBox extends RenderObject { ...@@ -653,6 +653,9 @@ abstract class RenderBox extends RenderObject {
@override @override
BoxConstraints get constraints => super.constraints; BoxConstraints get constraints => super.constraints;
// We check the intrinsic sizes of each render box once by default.
bool _debugNeedsIntrinsicSizeCheck = true;
@override @override
void debugAssertDoesMeetConstraints() { void debugAssertDoesMeetConstraints() {
assert(constraints != null); assert(constraints != null);
...@@ -716,43 +719,46 @@ abstract class RenderBox extends RenderObject { ...@@ -716,43 +719,46 @@ abstract class RenderBox extends RenderObject {
'your fault. Contact support: https://github.com/flutter/flutter/issues/new' 'your fault. Contact support: https://github.com/flutter/flutter/issues/new'
); );
} }
// verify that the intrinsics are also within the constraints if (_debugNeedsIntrinsicSizeCheck || debugCheckIntrinsicSizes) {
assert(!RenderObject.debugCheckingIntrinsics); // verify that the intrinsics are also within the constraints
RenderObject.debugCheckingIntrinsics = true; assert(!RenderObject.debugCheckingIntrinsics);
double intrinsic; RenderObject.debugCheckingIntrinsics = true;
StringBuffer failures = new StringBuffer(); double intrinsic;
int failureCount = 0; StringBuffer failures = new StringBuffer();
intrinsic = getMinIntrinsicWidth(constraints); int failureCount = 0;
if (intrinsic != constraints.constrainWidth(intrinsic)) { intrinsic = getMinIntrinsicWidth(constraints);
failures.writeln(' * getMinIntrinsicWidth() -- returned: w=$intrinsic'); if (intrinsic != constraints.constrainWidth(intrinsic)) {
failureCount += 1; failures.writeln(' * getMinIntrinsicWidth() -- returned: w=$intrinsic');
} failureCount += 1;
intrinsic = getMaxIntrinsicWidth(constraints); }
if (intrinsic != constraints.constrainWidth(intrinsic)) { intrinsic = getMaxIntrinsicWidth(constraints);
failures.writeln(' * getMaxIntrinsicWidth() -- returned: w=$intrinsic'); if (intrinsic != constraints.constrainWidth(intrinsic)) {
failureCount += 1; failures.writeln(' * getMaxIntrinsicWidth() -- returned: w=$intrinsic');
} failureCount += 1;
intrinsic = getMinIntrinsicHeight(constraints); }
if (intrinsic != constraints.constrainHeight(intrinsic)) { intrinsic = getMinIntrinsicHeight(constraints);
failures.writeln(' * getMinIntrinsicHeight() -- returned: h=$intrinsic'); if (intrinsic != constraints.constrainHeight(intrinsic)) {
failureCount += 1; failures.writeln(' * getMinIntrinsicHeight() -- returned: h=$intrinsic');
} failureCount += 1;
intrinsic = getMaxIntrinsicHeight(constraints); }
if (intrinsic != constraints.constrainHeight(intrinsic)) { intrinsic = getMaxIntrinsicHeight(constraints);
failures.writeln(' * getMaxIntrinsicHeight() -- returned: h=$intrinsic'); if (intrinsic != constraints.constrainHeight(intrinsic)) {
failureCount += 1; failures.writeln(' * getMaxIntrinsicHeight() -- returned: h=$intrinsic');
} failureCount += 1;
RenderObject.debugCheckingIntrinsics = false; }
if (failures.isNotEmpty) { RenderObject.debugCheckingIntrinsics = false;
assert(failureCount > 0); _debugNeedsIntrinsicSizeCheck = false;
throw new FlutterError( if (failures.isNotEmpty) {
'The intrinsic dimension methods of the $runtimeType class returned values that violate the given constraints.\n' assert(failureCount > 0);
'The constraints were: $constraints\n' throw new FlutterError(
'The following method${failureCount > 1 ? "s" : ""} returned values outside of those constraints:\n' 'The intrinsic dimension methods of the $runtimeType class returned values that violate the given constraints.\n'
'$failures' 'The constraints were: $constraints\n'
'If you are not writing your own RenderBox subclass, then this is not\n' 'The following method${failureCount > 1 ? "s" : ""} returned values outside of those constraints:\n'
'your fault. Contact support: https://github.com/flutter/flutter/issues/new' '$failures'
); 'If you are not writing your own RenderBox subclass, then this is not\n'
'your fault. Contact support: https://github.com/flutter/flutter/issues/new'
);
}
} }
return true; return true;
}); });
......
...@@ -68,6 +68,9 @@ bool debugPrintMarkNeedsPaintStacks = false; ...@@ -68,6 +68,9 @@ bool debugPrintMarkNeedsPaintStacks = false;
/// Log the call stacks that mark render objects as needing layout. /// Log the call stacks that mark render objects as needing layout.
bool debugPrintMarkNeedsLayoutStacks = false; bool debugPrintMarkNeedsLayoutStacks = false;
/// Check the intrinsic sizes of each [RenderBox] during layout.
bool debugCheckIntrinsicSizes = false;
List<String> debugDescribeTransform(Matrix4 transform) { List<String> debugDescribeTransform(Matrix4 transform) {
List<String> matrix = transform.toString().split('\n').map((String s) => ' $s').toList(); List<String> matrix = transform.toString().split('\n').map((String s) => ' $s').toList();
matrix.removeLast(); matrix.removeLast();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment