Cache whether a type is a collection

Merged
SI
3mo ago
+59-21

Whether a value is a collection depends only on its type, but it was recomputed per value. With the default ignoreEmptyCollections this runs for every non null member value, array item and dictionary value, and anything that is not a non generic ICollection (every HashSet, dictionary key and value view, iterator, LINQ result and immutable collection) allocated a fresh Type[] from GetInterfaces and then made several LINQ passes over it with FullName string comparisons, for every occurrence of the same type.

The classification is now held in a ConcurrentDictionary keyed by type, leaving only the per value IsEmpty enumeration.

The added test cases all sit below the ICollection fast path, so they exercise the classification, and they pass unchanged against the previous implementation.