Short-circuit _debugCanPerformMutations if debugDoingLayout is false (#81246)

This commit is contained in:
Ian Hickson 2021-04-27 15:04:03 -07:00 committed by GitHub
parent 6beafa7b16
commit d1f02ae075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1359,11 +1359,18 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
/// Whether tree mutations are currently permitted.
///
/// Only valid when asserts are enabled. In release builds, always returns
/// null.
/// This is only useful during layout. One should also not mutate the tree at
/// other times (e.g. during paint or while assembling the semantic tree) but
/// this function does not currently enforce those conventions.
///
/// Only valid when asserts are enabled. This will throw in release builds.
bool get _debugCanPerformMutations {
late bool result;
assert(() {
if (owner != null && !owner!.debugDoingLayout) {
result = true;
return true;
}
RenderObject node = this;
while (true) {
if (node._doingThisLayoutWithCallback) {