Avoid some unnecessary dynamic sends with DDC in Intl message lookup
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=123047520
diff --git a/lib/message_lookup_by_library.dart b/lib/message_lookup_by_library.dart
index e2139fc..bf8adf3 100644
--- a/lib/message_lookup_by_library.dart
+++ b/lib/message_lookup_by_library.dart
@@ -12,11 +12,12 @@
/// examples.
library message_lookup_by_library;
-import 'intl.dart';
+import 'package:intl/intl.dart';
+import 'package:intl/src/intl_helpers.dart';
/// This is a message lookup mechanism that delegates to one of a collection
/// of individual [MessageLookupByLibrary] instances.
-class CompositeMessageLookup {
+class CompositeMessageLookup implements MessageLookup {
/// A map from locale names to the corresponding lookups.
Map<String, MessageLookupByLibrary> availableMessages = new Map();
@@ -60,7 +61,7 @@
/// If we do not already have a locale for [localeName] then
/// [findLocale] will be called and the result stored as the lookup
/// mechanism for that locale.
- addLocale(String localeName, Function findLocale) {
+ void addLocale(String localeName, Function findLocale) {
if (localeExists(localeName)) return;
var canonical = Intl.canonicalizedLocale(localeName);
var newLocale = findLocale(canonical);
diff --git a/lib/src/intl_helpers.dart b/lib/src/intl_helpers.dart
index df0ef8e..2362277 100644
--- a/lib/src/intl_helpers.dart
+++ b/lib/src/intl_helpers.dart
@@ -13,7 +13,7 @@
/// This is used as a marker for a locale data map that hasn't been initialized,
/// and will throw an exception on any usage that isn't the fallback
/// patterns/symbols provided.
-class UninitializedLocaleData<F> {
+class UninitializedLocaleData<F> implements MessageLookup {
final String message;
final F fallbackData;
const UninitializedLocaleData(this.message, this.fallbackData);
@@ -21,8 +21,9 @@
operator [](String key) =>
(key == 'en_US') ? fallbackData : _throwException();
- String lookupMessage(String message_str, String locale,
- String name, List args) => message_str;
+ String lookupMessage(
+ String message_str, String locale, String name, List args) =>
+ message_str;
/// Given an initial locale or null, returns the locale that will be used
/// for messages.
@@ -36,6 +37,14 @@
throw new LocaleDataException("Locale data has not been initialized"
", call $message.");
}
+
+ void addLocale(String localeName, Function findLocale) => _throwException();
+}
+
+abstract class MessageLookup {
+ String lookupMessage(
+ String message_str, String locale, String name, List args);
+ void addLocale(String localeName, Function findLocale);
}
class LocaleDataException implements Exception {
@@ -52,7 +61,7 @@
/// The internal mechanism for looking up messages. We expect this to be set
/// by the implementing package so that we're not dependent on its
/// implementation.
-dynamic messageLookup =
+MessageLookup messageLookup =
const UninitializedLocaleData('initializeMessages(<locale>)', null);
/// Initialize the message lookup mechanism. This is for internal use only.