@@ -271,12 +271,7 @@ class DataSourceReader {
271
271
List <E >? readListOrNull <E >(E f ()) {
272
272
int count = readInt ();
273
273
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 );
280
275
}
281
276
282
277
bool readBool () {
@@ -334,30 +329,32 @@ class DataSourceReader {
334
329
return null ;
335
330
}
336
331
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.
339
342
///
340
343
/// This is a convenience method to be used together with
341
344
/// [DataSinkWriter.writeStrings] .
342
- List <String >? readStrings ({ bool emptyAsNull = false } ) {
345
+ List <String >? readStringsOrNull ( ) {
343
346
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 );
350
349
}
351
350
352
351
/// 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.
355
353
///
356
354
/// This is a convenience method to be used together with
357
355
/// [DataSinkWriter.writeNameMap] .
358
- Map <Name , V >? readNameMap <V >(V f (), { bool emptyAsNull = false } ) {
356
+ Map <Name , V > readNameMap <V >(V f ()) {
359
357
int count = readInt ();
360
- if (count == 0 && emptyAsNull) return null ;
361
358
Map <Name , V > map = {};
362
359
for (int i = 0 ; i < count; i++ ) {
363
360
Name key = readMemberName ();
@@ -368,8 +365,7 @@ class DataSourceReader {
368
365
}
369
366
370
367
/// 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.
373
369
///
374
370
/// This is a convenience method to be used together with
375
371
/// [DataSinkWriter.writeStringMap] .
@@ -625,8 +621,7 @@ class DataSourceReader {
625
621
}
626
622
627
623
/// 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.
630
625
///
631
626
/// This is a convenience method to be used together with
632
627
/// [DataSinkWriter.writeTreeNodeMap] .
@@ -667,21 +662,6 @@ class DataSourceReader {
667
662
return null ;
668
663
}
669
664
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
-
685
665
/// Reads a map from kernel tree nodes to [V] values in the known [context]
686
666
/// from this data source, calling [f] to read each value from the data
687
667
/// source.
@@ -729,8 +709,7 @@ class DataSourceReader {
729
709
}
730
710
731
711
/// 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.
734
713
///
735
714
/// This is a convenience method to be used together with
736
715
/// [DataSinkWriter.writeTypeParameterNodes] .
@@ -1131,8 +1110,7 @@ class DataSourceReader {
1131
1110
}
1132
1111
1133
1112
/// 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.
1136
1114
///
1137
1115
/// This is a convenience method to be used together with
1138
1116
/// [DataSinkWriter.writeTypeVariableMap] .
@@ -1178,8 +1156,7 @@ class DataSourceReader {
1178
1156
}
1179
1157
1180
1158
/// 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.
1183
1160
///
1184
1161
/// This is a convenience method to be used together with
1185
1162
/// [DataSinkWriter.writeLocalMap] .
@@ -1295,8 +1272,7 @@ class DataSourceReader {
1295
1272
return null ;
1296
1273
}
1297
1274
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.
1300
1276
///
1301
1277
/// This is a convenience method to be used together with
1302
1278
/// [DataSinkWriter.writeConstants] .
0 commit comments