LCOV - code coverage report

Current view
top level - src/converters - in_place_converter.dart
Test
lcov.info
Date
2024-11-13
Legend
Lines
hit
not hit
Branches
taken
not taken
# not executed
HitTotalCoverage
Lines3434100.0%
Functions00-
Branches00-
Each row represents a line of source code
LineBranchHitsSource code
1import 'converter.dart';
2
3/// This converter converts items in lists and maps **in place**. It avoids
4/// creating a copy of the data to hold the conversion result. All items in
5/// the list/map are converted at the time the list/map is processed.
6final class InPlaceConverter extends Converter {
73 const InPlaceConverter(this.converter) : super();
8
9 final Converter converter;
10
111 @override
123 Cast<T> value<T>() => converter.value<T>();
13
141 @override
151 Cast<List<T>> list<T>([Cast<T>? cast]) {
162 final op = cast ?? value<T>();
175 return Converter.isIdentity<T>(op) ? converter.list<T>(op) : _toList(op);
181 }
19
201 @override
211 Cast<Map<K, V>> map<K, V>({Cast<K>? kcast, Cast<V>? vcast}) {
223 final kop = kcast ?? value<K>(), vop = vcast ?? value<V>();
233 return (!Converter.isIdentity<K>(kop) || Converter.isIdentity<V>(vop))
243 ? converter.map<K, V>(kcast: kop, vcast: vop)
252 : _toMap(vop);
261 }
27
282 static Cast<List<T>> _toList<T>(Cast<T> cast) {
292 return (x) {
302 final y = Converter.toList(x);
315 for (var i = y.length - 1; i >= 0; i--) {
322 final v = y[i];
333 y[i] = (v == null) ? v : cast(v);
34 }
352 return y.cast<T>();
361 };
371 }
38
392 Cast<Map<K, V>> _toMap<K, V>(Cast<V> vcast) {
402 return (x) {
41 x as Map;
422 final keys = x.keys.toList();
435 for (var i = keys.length - 1; i >= 0; i--) {
443 final k = keys[i], v = x[k];
451 if (v != null) {
463 x[k] = vcast(v);
47 }
48 }
492 return x.cast<K, V>();
501 };
511 }
52}
Choose Features