cloneList<E> method

  1. @override
List<E> cloneList<E>(
  1. List<E> source
)
override

Return a deep-cloned List.

When doTypedClone is true the returned list performs typed cloning of elements. Typed cloning will throw UnsupportedTypedCloneException if a nested Map is encountered.

Preserves UnmodifiableListView by wrapping the cloned list.

Implementation

@override
List<E> cloneList<E>(List<E> source) {
  final isUnmodifiable = source is UnmodifiableListView<E>;
  final List<E> cloned;
  if (doTypedClone) {
    final len = source.length;
    cloned = source.toList();
    for (int i = 0; i < len; i++) {
      cloned[i] = _cloneValueTyped(source[i]);
    }
  } else {
    cloned = [for (final e in source) cloneValue(e)];
  }
  return isUnmodifiable ? UnmodifiableListView<E>(cloned) : cloned;
}