Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable non-allocating enumeration via collection interfaces
Interfaces like `IEnumerable<T>`, `IList<T>` and `IDictionary<TKey, TValue>` are used in many APIs. The upside of this is that the implementation of these APIs may change the concrete type of the collection as it sees fit without breaking consumers. The downside of this is that some operations through the interface are more expensive than if they were performed directly on the concrete type. Enumeration is perhaps the biggest challege here, as enumerating through these interfaces with `foreach` always requires a heap allocation. Most concrete implementations these implementations will be types such as `List<T>` and `Dictionary<TKey,TValue>` which have a non-allocating struct enumerators. This change adds `NoAllocEnumerate()` extension methods that avoid any enumerator allocation when the concrete collection type is known to have such a struct enumerator at runtime.
- Loading branch information