diff --git a/engine/src/flutter/lib/ui/fixtures/ui_test.dart b/engine/src/flutter/lib/ui/fixtures/ui_test.dart index 032e227b87..b0c7cdb697 100644 --- a/engine/src/flutter/lib/ui/fixtures/ui_test.dart +++ b/engine/src/flutter/lib/ui/fixtures/ui_test.dart @@ -450,6 +450,14 @@ void hooksTests() { } }); + test('deprecated region equals', () { + // These are equal because ZR is deprecated and was mapped to CD. + const Locale x = Locale('en', 'ZR'); + const Locale y = Locale('en', 'CD'); + expectEquals(x, y); + expectEquals(x.countryCode, y.countryCode); + }); + test('Window padding/insets/viewPadding/systemGestureInsets', () { _callHook( '_updateWindowMetrics', diff --git a/engine/src/flutter/lib/ui/platform_dispatcher.dart b/engine/src/flutter/lib/ui/platform_dispatcher.dart index 0ae3d6ae49..ef22df4bae 100644 --- a/engine/src/flutter/lib/ui/platform_dispatcher.dart +++ b/engine/src/flutter/lib/ui/platform_dispatcher.dart @@ -1992,17 +1992,23 @@ class Locale { if (other is! Locale) { return false; } - final String? countryCode = _countryCode; + final String? thisCountryCode = countryCode; final String? otherCountryCode = other.countryCode; return other.languageCode == languageCode && other.scriptCode == scriptCode // scriptCode cannot be '' - && (other.countryCode == countryCode // Treat '' as equal to null. - || otherCountryCode != null && otherCountryCode.isEmpty && countryCode == null - || countryCode != null && countryCode.isEmpty && other.countryCode == null); + && (other.countryCode == thisCountryCode // Treat '' as equal to null. + || otherCountryCode != null && otherCountryCode.isEmpty && thisCountryCode == null + || thisCountryCode != null && thisCountryCode.isEmpty && other.countryCode == null); } @override - int get hashCode => hashValues(languageCode, scriptCode, countryCode == '' ? null : countryCode); + int get hashCode => _hashCode[this] ??= hashValues( + languageCode, + scriptCode, + countryCode == '' ? null : countryCode, + ); + // Memoize hashCode since languageCode and countryCode require lookups. + static final Expando _hashCode = Expando(); static Locale? _cachedLocale; static String? _cachedLocaleString;