cloneValue method

  1. @override
dynamic cloneValue(
  1. dynamic source
)
override

Deep-clone source when possible.

Dispatching order:

  • null -> returned unchanged.
  • ICloneable -> delegates to the instance clone() method.
  • List, Set, Map -> produces a deep copy of the collection and its elements/values.

Performance:

  • O(n) where n is the total number of elements/entries in the structure.
  • creates new collections at each level, so memory usage is proportional to structure size.

Implementation

@override
dynamic cloneValue(dynamic source) {
  if (source == null) return source;
  if (source is ICloneable) return source.clone();
  if (source is List) return cloneList(source);
  if (source is Set) return cloneSet(source);
  if (source is Map) return cloneMap(source);
  return source;
}