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()
6363 ArgumentNullException . ThrowIfNull ( source ) ;
6464 ArgumentNullException . For < TKey > . ThrowIfNull ( key ) ;
6565
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.
6672 if ( source . TryGetList ( out List < ObservableGroup < TKey , TElement > > ? list ) )
6773 {
6874 foreach ( ObservableGroup < TKey , TElement > group in list )
You can’t perform that action at this time.
0 commit comments