From 4eefced8bc0e6f3e7da96dfe58407b4623e1fd3f Mon Sep 17 00:00:00 2001 From: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com> Date: Fri, 12 May 2023 01:05:20 -0700 Subject: [PATCH] Fix TextSpan gc regression (#126382) `for (final InlineSpan child in children ?? const [])` bad Fixes https://github.com/flutter/flutter/issues/126337 --- .../flutter/lib/src/painting/text_span.dart | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/packages/flutter/lib/src/painting/text_span.dart b/packages/flutter/lib/src/painting/text_span.dart index 59d4806ef1..34168be205 100644 --- a/packages/flutter/lib/src/painting/text_span.dart +++ b/packages/flutter/lib/src/painting/text_span.dart @@ -289,12 +289,15 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati builder.addText('\uFFFD'); } } - for (final InlineSpan child in children ?? const []) { - child.build( - builder, - textScaleFactor: textScaleFactor, - dimensions: dimensions, - ); + final List? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + child.build( + builder, + textScaleFactor: textScaleFactor, + dimensions: dimensions, + ); + } } if (hasStyle) { builder.pop(); @@ -311,9 +314,12 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati if (text != null && !visitor(this)) { return false; } - for (final InlineSpan child in children ?? const []) { - if (!child.visitChildren(visitor)) { - return false; + final List? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + if (!child.visitChildren(visitor)) { + return false; + } } } return true; @@ -321,9 +327,12 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati @override bool visitDirectChildren(InlineSpanVisitor visitor) { - for (final InlineSpan child in children ?? const []) { - if (!visitor(child)) { - return false; + final List? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + if (!visitor(child)) { + return false; + } } } return true; @@ -393,15 +402,18 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati recognizer: recognizer, )); } - for (final InlineSpan child in children ?? const []) { - if (child is TextSpan) { - child.computeSemanticsInformation( - collector, - inheritedLocale: effectiveLocale, - inheritedSpellOut: effectiveSpellOut, - ); - } else { - child.computeSemanticsInformation(collector); + final List? children = this.children; + if (children != null) { + for (final InlineSpan child in children) { + if (child is TextSpan) { + child.computeSemanticsInformation( + collector, + inheritedLocale: effectiveLocale, + inheritedSpellOut: effectiveSpellOut, + ); + } else { + child.computeSemanticsInformation(collector); + } } } }