Skip to content

Commit 3d40816

Browse files
natebiggsCommit Queue
authored and
Commit Queue
committed
[dart2js] Remove deserializer 'emptyAsNull' pattern.
Change-Id: I5b5e668fa6c1c261503de55f70aab966ca9df66f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338300 Reviewed-by: Mayank Patke <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent 7b12b23 commit 3d40816

File tree

8 files changed

+33
-57
lines changed

8 files changed

+33
-57
lines changed

pkg/compiler/lib/src/common/codegen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class _CodegenImpact extends WorldImpactBuilderImpl implements CodegenImpact {
118118
final typeVariableBoundsSubtypeChecks = source.readListOrNull(() {
119119
return Pair(source.readDartType(), source.readDartType());
120120
})?.toSet();
121-
final constSymbols = source.readStrings(emptyAsNull: true)?.toSet();
121+
final constSymbols = source.readStringsOrNull()?.toSet();
122122
final specializedGetInterceptors = source.readListOrNull(() {
123123
return source.readClasses().toSet();
124124
});

pkg/compiler/lib/src/elements/entities.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,9 @@ class ParameterStructure {
360360
source.begin(tag);
361361
int requiredPositionalParameters = source.readInt();
362362
int positionalParameters = source.readInt();
363-
List<String> namedParameters = source.readStrings()!;
363+
List<String> namedParameters = source.readStrings();
364364
Set<String> requiredNamedParameters =
365-
source.readStrings(emptyAsNull: true)?.toSet() ?? const <String>{};
365+
source.readStringsOrNull()?.toSet() ?? const <String>{};
366366
int typeParameters = source.readInt();
367367
source.end(tag);
368368
return ParameterStructure(

pkg/compiler/lib/src/ir/impact_data.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1562,7 +1562,7 @@ class _CallStructure {
15621562
source.begin(tag);
15631563
List<ir.DartType> typeArguments = source.readDartTypeNodes();
15641564
int positionalArguments = source.readInt();
1565-
List<String> namedArguments = source.readStrings() ?? const [];
1565+
List<String> namedArguments = source.readStrings();
15661566
source.end(tag);
15671567
return _CallStructure.internal(
15681568
typeArguments, positionalArguments, namedArguments);

pkg/compiler/lib/src/js_backend/native_data.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ class NativeBasicData {
233233
bool isAllowInteropUsed = source.readBool();
234234
Map<ClassEntity, NativeClassTag> nativeClassTagInfo =
235235
source.readClassMap(() {
236-
final names = source.readStrings()!;
236+
final names = source.readStrings();
237237
bool isNonLeaf = source.readBool();
238238
return NativeClassTag.internal(names, isNonLeaf);
239239
});

pkg/compiler/lib/src/js_model/env.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class JClassEnvImpl implements JClassEnv {
258258
ir.Class cls = source.readClassNode();
259259
Map<String, ir.Member> constructorMap =
260260
source.readStringMap(source.readMemberNode);
261-
Map<Name, ir.Member> memberMap = source.readNameMap(source.readMemberNode)!;
261+
Map<Name, ir.Member> memberMap = source.readNameMap(source.readMemberNode);
262262
List<ir.Member> members = source.readMemberNodes();
263263
bool isSuperMixinApplication = source.readBool();
264264
source.end(tag);
@@ -330,7 +330,7 @@ class ContextEnv implements JClassEnv {
330330
factory ContextEnv.readFromDataSource(DataSourceReader source) {
331331
source.begin(tag);
332332
Map<Name, MemberEntity> _memberMap =
333-
source.readNameMap(() => source.readMember())!;
333+
source.readNameMap(() => source.readMember());
334334
source.end(tag);
335335
return ContextEnv(_memberMap);
336336
}
@@ -390,7 +390,7 @@ class ClosureClassEnv extends ContextEnv {
390390
factory ClosureClassEnv.readFromDataSource(DataSourceReader source) {
391391
source.begin(tag);
392392
Map<Name, MemberEntity> _memberMap =
393-
source.readNameMap(() => source.readMember())!;
393+
source.readNameMap(() => source.readMember());
394394
source.end(tag);
395395
return ClosureClassEnv(_memberMap);
396396
}
@@ -416,7 +416,7 @@ class RecordClassEnv implements JClassEnv {
416416
factory RecordClassEnv.readFromDataSource(DataSourceReader source) {
417417
source.begin(tag);
418418
Map<Name, MemberEntity> _memberMap =
419-
source.readNameMap(() => source.readMember())!;
419+
source.readNameMap(() => source.readMember());
420420
source.end(tag);
421421
return RecordClassEnv(_memberMap);
422422
}

pkg/compiler/lib/src/serialization/source.dart

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,7 @@ class DataSourceReader {
271271
List<E>? readListOrNull<E>(E f()) {
272272
int count = readInt();
273273
if (count == 0) return null;
274-
final first = f();
275-
List<E> list = List<E>.filled(count, first);
276-
for (int i = 1; i < count; i++) {
277-
list[i] = f();
278-
}
279-
return list;
274+
return List<E>.generate(count, (_) => f(), growable: false);
280275
}
281276

282277
bool readBool() {
@@ -334,30 +329,32 @@ class DataSourceReader {
334329
return null;
335330
}
336331

337-
/// Reads a list of string values from this data source. If [emptyAsNull] is
338-
/// `true`, `null` is returned instead of an empty list.
332+
/// Reads a list of string values from this data source.
333+
///
334+
/// This is a convenience method to be used together with
335+
/// [DataSinkWriter.writeStrings].
336+
List<String> readStrings() {
337+
return readStringsOrNull() ?? const <String>[];
338+
}
339+
340+
/// Reads a list of string values from this data source. If the list would be
341+
/// empty returns `null` instead.
339342
///
340343
/// This is a convenience method to be used together with
341344
/// [DataSinkWriter.writeStrings].
342-
List<String>? readStrings({bool emptyAsNull = false}) {
345+
List<String>? readStringsOrNull() {
343346
int count = readInt();
344-
if (count == 0 && emptyAsNull) return null;
345-
List<String> list = List<String>.filled(count, '');
346-
for (int i = 0; i < count; i++) {
347-
list[i] = readString();
348-
}
349-
return list;
347+
if (count == 0) return null;
348+
return List.generate(count, (_) => readString(), growable: false);
350349
}
351350

352351
/// Reads a map from [Name] values to [V] values from this data source,
353-
/// calling [f] to read each value from the data source. If [emptyAsNull] is
354-
/// `true`, `null` is returned instead of an empty map.
352+
/// calling [f] to read each value from the data source.
355353
///
356354
/// This is a convenience method to be used together with
357355
/// [DataSinkWriter.writeNameMap].
358-
Map<Name, V>? readNameMap<V>(V f(), {bool emptyAsNull = false}) {
356+
Map<Name, V> readNameMap<V>(V f()) {
359357
int count = readInt();
360-
if (count == 0 && emptyAsNull) return null;
361358
Map<Name, V> map = {};
362359
for (int i = 0; i < count; i++) {
363360
Name key = readMemberName();
@@ -368,8 +365,7 @@ class DataSourceReader {
368365
}
369366

370367
/// Reads a map from string values to [V] values from this data source,
371-
/// calling [f] to read each value from the data source. If [emptyAsNull] is
372-
/// `true`, `null` is returned instead of an empty map.
368+
/// calling [f] to read each value from the data source.
373369
///
374370
/// This is a convenience method to be used together with
375371
/// [DataSinkWriter.writeStringMap].
@@ -625,8 +621,7 @@ class DataSourceReader {
625621
}
626622

627623
/// Reads a map from kernel tree nodes to [V] values from this data source,
628-
/// calling [f] to read each value from the data source. If [emptyAsNull] is
629-
/// `true`, `null` is returned instead of an empty map.
624+
/// calling [f] to read each value from the data source.
630625
///
631626
/// This is a convenience method to be used together with
632627
/// [DataSinkWriter.writeTreeNodeMap].
@@ -667,21 +662,6 @@ class DataSourceReader {
667662
return null;
668663
}
669664

670-
/// Reads a list of references to kernel tree nodes in the known [context]
671-
/// from this data source. If [emptyAsNull] is `true`, `null` is returned
672-
/// instead of an empty list.
673-
///
674-
/// This is a convenience method to be used together with
675-
/// [DataSinkWriter.writeTreeNodesInContext].
676-
List<E>? readTreeNodesInContext<E extends ir.TreeNode>(
677-
{bool emptyAsNull = false}) {
678-
int count = readInt();
679-
if (count == 0 && emptyAsNull) return null;
680-
return List<E>.generate(
681-
count, (index) => readTreeNodeInContextInternal(currentMemberData) as E,
682-
growable: false);
683-
}
684-
685665
/// Reads a map from kernel tree nodes to [V] values in the known [context]
686666
/// from this data source, calling [f] to read each value from the data
687667
/// source.
@@ -729,8 +709,7 @@ class DataSourceReader {
729709
}
730710

731711
/// Reads a list of references to kernel type parameter nodes from this data
732-
/// source. If [emptyAsNull] is `true`, `null` is returned instead of an empty
733-
/// list.
712+
/// source.
734713
///
735714
/// This is a convenience method to be used together with
736715
/// [DataSinkWriter.writeTypeParameterNodes].
@@ -1131,8 +1110,7 @@ class DataSourceReader {
11311110
}
11321111

11331112
/// Reads a map from type variable entities to [V] values from this data
1134-
/// source, calling [f] to read each value from the data source. If
1135-
/// [emptyAsNull] is `true`, `null` is returned instead of an empty map.
1113+
/// source, calling [f] to read each value from the data source.
11361114
///
11371115
/// This is a convenience method to be used together with
11381116
/// [DataSinkWriter.writeTypeVariableMap].
@@ -1178,8 +1156,7 @@ class DataSourceReader {
11781156
}
11791157

11801158
/// Reads a map from locals to [V] values from this data source, calling [f]
1181-
/// to read each value from the data source. If [emptyAsNull] is `true`,
1182-
/// `null` is returned instead of an empty map.
1159+
/// to read each value from the data source.
11831160
///
11841161
/// This is a convenience method to be used together with
11851162
/// [DataSinkWriter.writeLocalMap].
@@ -1295,8 +1272,7 @@ class DataSourceReader {
12951272
return null;
12961273
}
12971274

1298-
/// Reads a list of constant values from this data source. If [emptyAsNull] is
1299-
/// `true`, `null` is returned instead of an empty list.
1275+
/// Reads a list of constant values from this data source.
13001276
///
13011277
/// This is a convenience method to be used together with
13021278
/// [DataSinkWriter.writeConstants].

pkg/compiler/lib/src/universe/call_structure.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class CallStructure {
8585
factory CallStructure.readFromDataSource(DataSourceReader source) {
8686
source.begin(tag);
8787
int argumentCount = source.readInt();
88-
List<String> namedArguments = source.readStrings()!;
88+
List<String> namedArguments = source.readStrings();
8989
int typeArgumentCount = source.readInt();
9090
source.end(tag);
9191
return CallStructure(argumentCount, namedArguments, typeArgumentCount);

pkg/compiler/lib/src/universe/record_shape.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class RecordShape {
6666
factory RecordShape.readFromDataSource(DataSourceReader source) {
6767
source.begin(tag);
6868
int positionals = source.readInt();
69-
List<String> names = source.readStrings()!;
69+
List<String> names = source.readStrings();
7070
source.end(tag);
7171
return RecordShape(positionals, names);
7272
}

0 commit comments

Comments
 (0)