[dart2js] Modernize allocations in js_emitter/
Change-Id: Iecdde5c8940ede24f4ac428a624984a0b2ca4f97
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213963
Commit-Queue: Stephen Adams <sra@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
diff --git a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
index ff79ce8..21e2959 100644
--- a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
@@ -73,13 +73,12 @@
}
}
- Map<jsAst.Name, jsAst.Expression> generatedStubs =
- <jsAst.Name, jsAst.Expression>{};
+ Map<jsAst.Name, jsAst.Expression> generatedStubs = {};
// Two selectors may match but differ only in type. To avoid generating
// identical stubs for each we track untyped selectors which already have
// stubs.
- Set<Selector> generatedSelectors = Set<Selector>();
+ Set<Selector> generatedSelectors = {};
for (Selector selector in selectors.keys) {
if (generatedSelectors.contains(selector)) continue;
if (!selector.appliesUnnamed(member)) continue;
@@ -91,8 +90,8 @@
Selector callSelector = Selector.callClosureFrom(selector);
jsAst.Name closureCallName = _namer.invocationName(callSelector);
- List<jsAst.Parameter> parameters = <jsAst.Parameter>[];
- List<jsAst.Expression> arguments = <jsAst.Expression>[];
+ List<jsAst.Parameter> parameters = [];
+ List<jsAst.Expression> arguments = [];
if (isInterceptedMethod) {
parameters.add(jsAst.Parameter(receiverArgumentName));
}
@@ -120,7 +119,7 @@
}
Map<jsAst.Name, Selector> computeSelectorsForNsmHandlers() {
- Map<jsAst.Name, Selector> jsNames = <jsAst.Name, Selector>{};
+ Map<jsAst.Name, Selector> jsNames = {};
// Do not generate no such method handlers if there is no class.
if (_codegenWorld.directlyInstantiatedClasses.isEmpty) {
diff --git a/pkg/compiler/lib/src/js_emitter/instantiation_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/instantiation_stub_generator.dart
index 56dc803..627dbe5 100644
--- a/pkg/compiler/lib/src/js_emitter/instantiation_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/instantiation_stub_generator.dart
@@ -69,8 +69,8 @@
// }
// ```
- List<jsAst.Parameter> parameters = <jsAst.Parameter>[];
- List<jsAst.Expression> arguments = <jsAst.Expression>[];
+ List<jsAst.Parameter> parameters = [];
+ List<jsAst.Expression> arguments = [];
for (int i = 0; i < callSelector.argumentCount; i++) {
String jsName = 'a$i';
@@ -156,7 +156,7 @@
_codegenWorld.invocationsByName(call);
Set<ParameterStructure> computeLiveParameterStructures() {
- Set<ParameterStructure> parameterStructures = Set<ParameterStructure>();
+ Set<ParameterStructure> parameterStructures = {};
void process(FunctionEntity function) {
if (function.parameterStructure.typeParameters == typeArgumentCount) {
@@ -171,7 +171,7 @@
return parameterStructures;
}
- List<StubMethod> stubs = <StubMethod>[];
+ List<StubMethod> stubs = [];
// For every call-selector generate a stub to the corresponding selector
// with filled-in type arguments.
diff --git a/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
index 0667034..b96d0e8 100644
--- a/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
@@ -133,7 +133,7 @@
hasNative = anyNativeClasses;
}
- List<jsAst.Statement> statements = <jsAst.Statement>[];
+ List<jsAst.Statement> statements = [];
if (hasNumber) {
jsAst.Statement whenNumber;
@@ -220,7 +220,7 @@
// chance of making the dispatch record access monomorphic.
jsAst.PropertyAccess record = jsAst.PropertyAccess(use2, dispatchProperty);
- List<jsAst.Expression> arguments = <jsAst.Expression>[use1, record];
+ List<jsAst.Expression> arguments = [use1, record];
FunctionEntity helper = _commonElements.isJsIndexable;
jsAst.Expression helperExpression = _emitter.staticFunctionAccess(helper);
return jsAst.Call(helperExpression, arguments);
@@ -382,7 +382,7 @@
Set<ClassEntity> classes = interceptor.classes;
jsAst.Name getInterceptorName = _namer.nameForGetInterceptor(classes);
- List<String> parameterNames = <String>[];
+ List<String> parameterNames = [];
parameterNames.add('receiver');
if (selector.isSetter) {
@@ -401,7 +401,7 @@
jsAst.Statement optimizedPath =
_fastPathForOneShotInterceptor(selector, classes);
- if (optimizedPath == null) optimizedPath = js.statement(';');
+ optimizedPath ??= js.statement(';');
return js('function(#) { #; return #.#(receiver).#(#) }', [
parameterNames,
@@ -418,7 +418,7 @@
CustomElementsCodegenAnalysis analysis = _customElementsCodegenAnalysis;
if (!analysis.needsTable) return null;
- List<jsAst.Expression> elements = <jsAst.Expression>[];
+ List<jsAst.Expression> elements = [];
Iterable<ConstantValue> constants =
_codegenWorld.getConstantsForEmission(_emitter.compareConstants);
for (ConstantValue constant in constants) {
diff --git a/pkg/compiler/lib/src/js_emitter/metadata_collector.dart b/pkg/compiler/lib/src/js_emitter/metadata_collector.dart
index 3012b85..5023420 100644
--- a/pkg/compiler/lib/src/js_emitter/metadata_collector.dart
+++ b/pkg/compiler/lib/src/js_emitter/metadata_collector.dart
@@ -120,8 +120,7 @@
// Merge _metadataMap
var sourceMetadataMap = _metadataMap[source];
if (sourceMetadataMap != null) {
- var targetMetadataMap =
- _metadataMap[target] ??= Map<String, List<BoundMetadataEntry>>();
+ var targetMetadataMap = _metadataMap[target] ??= {};
_metadataMap.remove(source);
sourceMetadataMap.forEach((str, entries) {
var targetMetadataMapList = targetMetadataMap[str] ??= [];
@@ -132,8 +131,7 @@
// Merge _typesMap
var sourceTypesMap = _typesMap[source];
if (sourceTypesMap != null) {
- var targetTypesMap =
- _typesMap[target] ??= Map<DartType, List<BoundMetadataEntry>>();
+ var targetTypesMap = _typesMap[target] ??= {};
_typesMap.remove(source);
sourceTypesMap.forEach((type, entries) {
var targetTypesMapList = targetTypesMap[type] ??= [];
@@ -152,7 +150,7 @@
}
jsAst.Expression _addTypeInOutputUnit(DartType type, OutputUnit outputUnit) {
- _typesMap[outputUnit] ??= Map<DartType, List<BoundMetadataEntry>>();
+ _typesMap[outputUnit] ??= {};
BoundMetadataEntry metadataEntry;
if (_typesMap[outputUnit].containsKey(type)) {
diff --git a/pkg/compiler/lib/src/js_emitter/model.dart b/pkg/compiler/lib/src/js_emitter/model.dart
index bf31927..706385f 100644
--- a/pkg/compiler/lib/src/js_emitter/model.dart
+++ b/pkg/compiler/lib/src/js_emitter/model.dart
@@ -309,7 +309,7 @@
_mixinClass = mixinClass;
}
- js.Name get superclassName => superclass == null ? null : superclass.name;
+ js.Name get superclassName => superclass?.name;
@override
String toString() => 'Class(name=${name.key},element=$element)';
diff --git a/pkg/compiler/lib/src/js_emitter/native_emitter.dart b/pkg/compiler/lib/src/js_emitter/native_emitter.dart
index 87b1847..a3137e7 100644
--- a/pkg/compiler/lib/src/js_emitter/native_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/native_emitter.dart
@@ -27,15 +27,13 @@
bool hasNativeClasses = false;
// Caches the native subtypes of a native class.
- Map<ClassEntity, List<ClassEntity>> subtypes =
- <ClassEntity, List<ClassEntity>>{};
+ Map<ClassEntity, List<ClassEntity>> subtypes = {};
// Caches the direct native subtypes of a native class.
- Map<ClassEntity, List<ClassEntity>> directSubtypes =
- <ClassEntity, List<ClassEntity>>{};
+ Map<ClassEntity, List<ClassEntity>> directSubtypes = {};
// Caches the methods that have a native body.
- Set<FunctionEntity> nativeMethods = Set<FunctionEntity>();
+ Set<FunctionEntity> nativeMethods = {};
// Type metadata redirections, where the key is the class type data being
// redirected to and the value is the list of class type data being
@@ -91,8 +89,8 @@
// Compute a pre-order traversal of the subclass forest. We actually want a
// post-order traversal but it is easier to compute the pre-order and use it
// in reverse.
- List<Class> preOrder = <Class>[];
- Set<Class> seen = Set<Class>();
+ List<Class> preOrder = [];
+ Set<Class> seen = {};
Class objectClass = null;
Class jsInterceptorClass = null;
@@ -119,8 +117,8 @@
// needed class.
// We may still need to include type metadata for some unneeded classes.
- Set<Class> neededClasses = Set<Class>();
- Set<Class> nonLeafClasses = Set<Class>();
+ Set<Class> neededClasses = {};
+ Set<Class> nonLeafClasses = {};
Map<Class, List<Class>> extensionPoints = computeExtensionPoints(preOrder);
@@ -177,8 +175,8 @@
// Collect all the tags that map to each native class.
- Map<Class, Set<String>> leafTags = Map<Class, Set<String>>();
- Map<Class, Set<String>> nonleafTags = Map<Class, Set<String>>();
+ Map<Class, Set<String>> leafTags = {};
+ Map<Class, Set<String>> nonleafTags = {};
for (Class cls in classes) {
if (!cls.isNative) continue;
@@ -187,7 +185,7 @@
List<String> nativeTags = _nativeData.getNativeTagsOfClass(cls.element);
if (nonLeafClasses.contains(cls) || extensionPoints.containsKey(cls)) {
- nonleafTags.putIfAbsent(cls, () => Set<String>()).addAll(nativeTags);
+ nonleafTags.putIfAbsent(cls, () => {}).addAll(nativeTags);
} else {
Class sufficingInterceptor = cls;
while (!neededClasses.contains(sufficingInterceptor)) {
@@ -196,9 +194,7 @@
if (sufficingInterceptor == objectClass) {
sufficingInterceptor = jsInterceptorClass;
}
- leafTags
- .putIfAbsent(sufficingInterceptor, () => Set<String>())
- .addAll(nativeTags);
+ leafTags.putIfAbsent(sufficingInterceptor, () => {}).addAll(nativeTags);
}
}
@@ -250,13 +246,13 @@
return nativeSuperclassOf(cls.superclass);
}
- Map<Class, List<Class>> map = Map<Class, List<Class>>();
+ Map<Class, List<Class>> map = {};
for (Class cls in classes) {
if (cls.isNative) continue;
Class nativeAncestor = nativeAncestorOf(cls);
if (nativeAncestor != null) {
- map.putIfAbsent(nativeAncestor, () => <Class>[]).add(cls);
+ map.putIfAbsent(nativeAncestor, () => []).add(cls);
}
}
return map;
@@ -319,7 +315,7 @@
// must be turned into a JS call to:
// foo(null, y).
- List<jsAst.Statement> statements = <jsAst.Statement>[];
+ List<jsAst.Statement> statements = [];
potentiallyConvertDartClosuresToJs(statements, member, stubParameters);
String target;
diff --git a/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart
index 94e356e..022cd5a 100644
--- a/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/parameter_stub_generator.dart
@@ -28,7 +28,7 @@
import 'native_emitter.dart';
class ParameterStubGenerator {
- static final Set<Selector> emptySelectorSet = Set<Selector>();
+ static final Set<Selector> emptySelectorSet = {};
final Emitter _emitter;
final NativeEmitter _nativeEmitter;
@@ -301,10 +301,10 @@
}
assert(emptySelectorSet.isEmpty);
- liveSelectors ??= const <Selector, SelectorConstraints>{};
- callSelectors ??= const <Selector, SelectorConstraints>{};
+ liveSelectors ??= const {};
+ callSelectors ??= const {};
- List<ParameterStubMethod> stubs = <ParameterStubMethod>[];
+ List<ParameterStubMethod> stubs = [];
if (liveSelectors.isEmpty &&
callSelectors.isEmpty &&
@@ -318,9 +318,9 @@
//
// For example, for the call-selector `call(x, y)` the renamed selector
// for member `foo` would be `foo(x, y)`.
- Set<Selector> renamedCallSelectors = Set<Selector>();
+ Set<Selector> renamedCallSelectors = {};
- Set<Selector> stubSelectors = Set<Selector>();
+ Set<Selector> stubSelectors = {};
// Start with closure-call selectors, since since they imply the generation
// of the non-call version.
diff --git a/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart b/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
index 6ed1763..7e64084 100644
--- a/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
+++ b/pkg/compiler/lib/src/js_emitter/program_builder/program_builder.dart
@@ -147,7 +147,7 @@
/// Mapping from [ClassEntity] to constructed [Class]. We need this to
/// update the superclass in the [Class].
- final Map<ClassEntity, Class> _classes = <ClassEntity, Class>{};
+ final Map<ClassEntity, Class> _classes = {};
/// Mapping from [ClassEntity] to constructed [ClassTypeData] object. Used to build
/// libraries.
@@ -155,11 +155,11 @@
/// Mapping from [OutputUnit] to constructed [Fragment]. We need this to
/// generate the deferredLoadingMap (to know which hunks to load).
- final Map<OutputUnit, Fragment> _outputs = <OutputUnit, Fragment>{};
+ final Map<OutputUnit, Fragment> _outputs = {};
/// Mapping from [ConstantValue] to constructed [Constant]. We need this to
/// update field-initializers to point to the ConstantModel.
- final Map<ConstantValue, Constant> _constants = <ConstantValue, Constant>{};
+ final Map<ConstantValue, Constant> _constants = {};
Set<Class> _unneededNativeClasses;
@@ -314,7 +314,7 @@
List<Constant> _buildConstants(LibrariesMap librariesMap) {
List<ConstantValue> constantValues =
collector.outputConstantLists[librariesMap.outputUnit];
- if (constantValues == null) return const <Constant>[];
+ if (constantValues == null) return const [];
return constantValues
.map((ConstantValue value) => _constants[value])
.toList(growable: false);
@@ -323,7 +323,7 @@
List<StaticField> _buildStaticNonFinalFields(LibrariesMap librariesMap) {
List<FieldEntity> staticNonFinalFields =
collector.outputStaticNonFinalFieldLists[librariesMap.outputUnit];
- if (staticNonFinalFields == null) return const <StaticField>[];
+ if (staticNonFinalFields == null) return const [];
return staticNonFinalFields.map(_buildStaticField).toList(growable: false);
}
@@ -604,7 +604,7 @@
}
}
- List<StubMethod> noSuchMethodStubs = <StubMethod>[];
+ List<StubMethod> noSuchMethodStubs = [];
if (_backendUsage.isNoSuchMethodUsed &&
cls == _commonElements.objectClass) {
@@ -635,7 +635,7 @@
bool isMixinApplicationWithMembers = false;
if (!onlyForConstructorOrRti) {
if (_elementEnvironment.isMixinApplicationWithMembers(cls)) {
- List<MemberEntity> members = <MemberEntity>[];
+ List<MemberEntity> members = [];
void add(MemberEntity member) {
if (member.enclosingClass == cls) {
members.add(member);
@@ -650,7 +650,7 @@
_sorter.sortMembers(members).forEach(visitMember);
}
} else if (!_elementEnvironment.isMixinApplication(cls)) {
- List<MemberEntity> members = <MemberEntity>[];
+ List<MemberEntity> members = [];
_elementEnvironment.forEachLocalClassMember(cls, members.add);
_elementEnvironment.forEachInjectedClassMember(cls, members.add);
_elementEnvironment.forEachConstructorBody(cls, members.add);
@@ -676,8 +676,8 @@
cls, _generatedCode,
storeFunctionTypeInMetadata: _storeFunctionTypesInMetadata);
- List<StubMethod> checkedSetters = <StubMethod>[];
- List<StubMethod> isChecks = <StubMethod>[];
+ List<StubMethod> checkedSetters = [];
+ List<StubMethod> isChecks = [];
if (_nativeData.isJsInteropClass(cls)) {
// TODO(johnniwinther): Instead of generating all stubs for each
// js-interop class we should generate a stub for each implemented class.
@@ -948,7 +948,7 @@
List<ParameterStubMethod> _generateParameterStubs(
FunctionEntity element, bool canTearOff, bool canBeApplied) {
- if (!_methodNeedsStubs(element)) return const <ParameterStubMethod>[];
+ if (!_methodNeedsStubs(element)) return const [];
ParameterStubGenerator generator = ParameterStubGenerator(
_task.emitter,
@@ -1025,7 +1025,7 @@
List<Field> _buildFields(
{bool isHolderInterceptedClass = false, ClassEntity cls}) {
- List<Field> fields = <Field>[];
+ List<Field> fields = [];
void visitField(FieldEntity field, js.Name name, bool needsGetter,
bool needsSetter, bool needsCheckedSetter) {
diff --git a/pkg/compiler/lib/src/js_emitter/program_builder/registry.dart b/pkg/compiler/lib/src/js_emitter/program_builder/registry.dart
index cc0ded7..78e6cd2 100644
--- a/pkg/compiler/lib/src/js_emitter/program_builder/registry.dart
+++ b/pkg/compiler/lib/src/js_emitter/program_builder/registry.dart
@@ -20,8 +20,7 @@
///
/// There exists exactly one instance per [OutputUnit].
class LibrariesMap {
- final Map<LibraryEntity, LibraryContents> _mapping =
- <LibraryEntity, LibraryContents>{};
+ final Map<LibraryEntity, LibraryContents> _mapping = {};
// It is very common to access the same library multiple times in a row, so
// we cache the last access.
@@ -78,8 +77,7 @@
class Registry {
final OutputUnit _mainOutputUnit;
final Sorter _sorter;
- final Map<OutputUnit, LibrariesMap> _deferredLibrariesMap =
- <OutputUnit, LibrariesMap>{};
+ final Map<OutputUnit, LibrariesMap> _deferredLibrariesMap = {};
/// Cache for the last seen output unit.
OutputUnit _lastOutputUnit;
diff --git a/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart b/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
index 47ba43a..ca7d511 100644
--- a/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/runtime_type_generator.dart
@@ -49,7 +49,7 @@
/// The properties that must be installed on the prototype of the
/// JS constructor of the [ClassEntity] for which the is checks were
/// generated.
- final Map<ClassEntity, TypeTests> _properties = <ClassEntity, TypeTests>{};
+ final Map<ClassEntity, TypeTests> _properties = {};
void addIsTest(ClassEntity cls, jsAst.Name name, jsAst.Node expression) {
TypeTests typeTests = _properties.putIfAbsent(cls, () => TypeTests());
@@ -187,7 +187,7 @@
ClassEntity cls,
FunctionTypeSignatureEmitter generateFunctionTypeSignature,
void emitTypeCheck(TypeCheck check)) {
- Setlet<ClassEntity> generated = Setlet<ClassEntity>();
+ Setlet<ClassEntity> generated = Setlet();
// Precomputed is checks.
ClassChecks classChecks = _rtiChecks.requiredChecks[cls];
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
index 2943ece..6bf7046 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
@@ -1201,7 +1201,7 @@
collect(superclass);
}
- subclasses.putIfAbsent(superclass, () => <Class>[]).add(cls);
+ subclasses.putIfAbsent(superclass, () => []).add(cls);
seen.add(cls);
}
@@ -1835,8 +1835,8 @@
// therefore unused in this emitter.
// TODO(johnniwinther): Remove the need for adding an empty list of
// mangled names.
- globals.add(js.Property(
- js.string(MANGLED_NAMES), js.ObjectInitializer(<js.Property>[])));
+ globals
+ .add(js.Property(js.string(MANGLED_NAMES), js.ObjectInitializer([])));
globals.addAll(emitMetadata(program));
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
index 9b48bd6..009853e 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
@@ -411,7 +411,7 @@
if (_shouldGenerateSourceMap) {
_task.measureSubtask('source-maps', () {
locationCollector = LocationCollector();
- codeOutputListeners = <CodeOutputListener>[locationCollector];
+ codeOutputListeners = [locationCollector];
});
}