Prepare flutter engine for enabling private final field promotion. (flutter/engine#43959)

Some parts of the flutter engine are built using the latest version of the Dart SDK, ignoring SDK constraints in `pubspec.yaml` files. Therefore, before the Dart SDK can switch on the "private field promotion" feature (https://github.com/dart-lang/language/issues/2020), these parts of the flutter engine need to be modified so that they won't have any "unnecessary `!`" warnings after field private field promotion is enabled. This PR makes the necessary changes.

This PR doesn't introduce any functional change. In principle it might improve performance slightly (by avoiding redundant memory accesses), but in practice the difference is unlikely to rise out of the measurement noise.

Issue fixed by this PR: https://github.com/flutter/flutter/issues/131198

[C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
Paul Berry
2023-07-25 18:04:09 -07:00
committed by GitHub
parent 971c360087
commit db661a120d
5 changed files with 46 additions and 32 deletions

View File

@@ -3589,10 +3589,11 @@ class ColorFilter implements ImageFilter {
}
return _ColorFilter.mode(this);
case _kTypeMatrix:
if (_matrix == null) {
final List<double>? matrix = _matrix;
if (matrix == null) {
return null;
}
assert(_matrix!.length == 20, 'Color Matrix must have 20 entries.');
assert(matrix.length == 20, 'Color Matrix must have 20 entries.');
return _ColorFilter.matrix(this);
case _kTypeLinearToSrgbGamma:
return _ColorFilter.linearToSrgbGamma(this);
@@ -3616,7 +3617,10 @@ class ColorFilter implements ImageFilter {
}
@override
int get hashCode => Object.hash(_color, _blendMode, _matrix == null ? null : Object.hashAll(_matrix!), _type);
int get hashCode {
final List<double>? matrix = _matrix;
return Object.hash(_color, _blendMode, matrix == null ? null : Object.hashAll(matrix), _type);
}
@override
String get _shortDescription {

View File

@@ -2315,8 +2315,9 @@ class Locale {
if (scriptCode != null && scriptCode!.isNotEmpty) {
out.write('$separator$scriptCode');
}
if (_countryCode != null && _countryCode!.isNotEmpty) {
out.write('$separator$countryCode');
final String? countryCode = _countryCode;
if (countryCode != null && countryCode.isNotEmpty) {
out.write('$separator${this.countryCode}');
}
return out.toString();
}

View File

@@ -1550,26 +1550,32 @@ class TextStyle {
}
@override
int get hashCode => Object.hash(
Object.hashAll(_encoded),
_leadingDistribution,
_fontFamily,
_fontFamilyFallback,
_fontSize,
_letterSpacing,
_wordSpacing,
_height,
_locale,
_background,
_foreground,
_shadows == null ? null : Object.hashAll(_shadows!),
_decorationThickness,
_fontFeatures == null ? null : Object.hashAll(_fontFeatures!),
_fontVariations == null ? null : Object.hashAll(_fontVariations!),
);
int get hashCode {
final List<Shadow>? shadows = _shadows;
final List<FontFeature>? fontFeatures = _fontFeatures;
final List<FontVariation>? fontVariations = _fontVariations;
return Object.hash(
Object.hashAll(_encoded),
_leadingDistribution,
_fontFamily,
_fontFamilyFallback,
_fontSize,
_letterSpacing,
_wordSpacing,
_height,
_locale,
_background,
_foreground,
shadows == null ? null : Object.hashAll(shadows),
_decorationThickness,
fontFeatures == null ? null : Object.hashAll(fontFeatures),
fontVariations == null ? null : Object.hashAll(fontVariations),
);
}
@override
String toString() {
final List<String>? fontFamilyFallback = _fontFamilyFallback;
return 'TextStyle('
'color: ${ _encoded[0] & 0x00002 == 0x00002 ? Color(_encoded[1]) : "unspecified"}, '
'decoration: ${ _encoded[0] & 0x00004 == 0x00004 ? TextDecoration._(_encoded[2]) : "unspecified"}, '
@@ -1583,8 +1589,8 @@ class TextStyle {
'fontFamily: ${ _encoded[0] & 0x00200 == 0x00200
&& _fontFamily != '' ? _fontFamily : "unspecified"}, '
'fontFamilyFallback: ${ _encoded[0] & 0x00200 == 0x00200
&& _fontFamilyFallback != null
&& _fontFamilyFallback!.isNotEmpty ? _fontFamilyFallback : "unspecified"}, '
&& fontFamilyFallback != null
&& fontFamilyFallback.isNotEmpty ? fontFamilyFallback : "unspecified"}, '
'fontSize: ${ _encoded[0] & 0x00400 == 0x00400 ? _fontSize : "unspecified"}, '
'letterSpacing: ${ _encoded[0] & 0x00800 == 0x00800 ? "${_letterSpacing}x" : "unspecified"}, '
'wordSpacing: ${ _encoded[0] & 0x01000 == 0x01000 ? "${_wordSpacing}x" : "unspecified"}, '
@@ -3185,8 +3191,9 @@ base class _NativeParagraphBuilder extends NativeFieldWrapperClass1 implements P
void pushStyle(TextStyle style) {
final List<String> fullFontFamilies = <String>[];
fullFontFamilies.add(style._fontFamily);
if (style._fontFamilyFallback != null) {
fullFontFamilies.addAll(style._fontFamilyFallback!);
final List<String>? fontFamilyFallback = style._fontFamilyFallback;
if (fontFamilyFallback != null) {
fullFontFamilies.addAll(fontFamilyFallback);
}
final Int32List encoded = style._encoded;

View File

@@ -98,9 +98,7 @@ class PlatformViewMessageHandler {
// For now, we don't need anything fancier. If needed, this can be converted
// to a PlatformViewStrategy class for each web-renderer backend?
if (_contentHandler != null) {
_contentHandler!(content);
}
_contentHandler?.call(content);
callback(_codec.encodeSuccessEnvelope(null));
}

View File

@@ -2122,14 +2122,15 @@ class EngineSemanticsOwner {
// First, update each object's information about itself. This information is
// later used to fix the parent-child and sibling relationships between
// objects.
for (final SemanticsNodeUpdate nodeUpdate in update._nodeUpdates!) {
final List<SemanticsNodeUpdate> nodeUpdates = update._nodeUpdates!;
for (final SemanticsNodeUpdate nodeUpdate in nodeUpdates) {
final SemanticsObject object = getOrCreateObject(nodeUpdate.id);
object.updateSelf(nodeUpdate);
}
// Second, fix the tree structure. This is moved out into its own loop,
// because each object's own information must be updated first.
for (final SemanticsNodeUpdate nodeUpdate in update._nodeUpdates!) {
for (final SemanticsNodeUpdate nodeUpdate in nodeUpdates) {
final SemanticsObject object = _semanticsTree[nodeUpdate.id]!;
object.updateChildren();
object._dirtyFields = 0;
@@ -2193,11 +2194,14 @@ class EngineSemanticsOwner {
});
// Validate that all updates were applied
for (final SemanticsNodeUpdate update in update._nodeUpdates!) {
for (final SemanticsNodeUpdate update in nodeUpdates) {
// Node was added to the tree.
assert(_semanticsTree.containsKey(update.id));
}
// Verify that `update._nodeUpdates` has not changed.
assert(identical(update._nodeUpdates, nodeUpdates));
return true;
}());
}