File tree Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Expand file tree Collapse file tree 1 file changed +6
-0
lines changed Original file line number Diff line number Diff line change @@ -63,6 +63,12 @@ static void ThrowArgumentExceptionForKeyNotFound()
63
63
ArgumentNullException . ThrowIfNull ( source ) ;
64
64
ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
65
65
66
+ // This pattern is used extensively in this file, with many of the public APIs having a first loop on the retrieved
67
+ // list, and then a fallback one sometimes with the same logic, but on the collection itself. This is done as an
68
+ // optimization: if a list is available, we can iterate on it directly, which will use List<T>.Enumerator and avoid
69
+ // allocations (the enumerator is a struct), additional indirections (the enumerator wraps the list instead of the
70
+ // outer collection, and additional overhead (using the value enumerator avoids the interface stub dispatches).
71
+ // Because of this, duplicate logic below is intentional and not actually duplicate, as it results in different code.
66
72
if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
67
73
{
68
74
foreach ( ObservableGroup < TKey , TElement > group in list )
You can’t perform that action at this time.
0 commit comments