1
0
Эх сурвалжийг харах

Save some state machine allocations.

Bart De Smet 7 жил өмнө
parent
commit
4e73c9a032

+ 9 - 4
Ix.NET/Source/System.Linq.Async/System/Linq/AsyncListPartition.cs

@@ -38,17 +38,22 @@ namespace System.Linq
             return new AsyncListPartition<TSource>(_source, _minIndexInclusive, _maxIndexInclusive);
         }
 
-        protected override async ValueTask<bool> MoveNextCore()
+        protected override ValueTask<bool> MoveNextCore()
         {
             if ((uint)_index <= (uint)(_maxIndexInclusive - _minIndexInclusive) && _index < _source.Count - _minIndexInclusive)
             {
                 _current = _source[_minIndexInclusive + _index];
                 ++_index;
-                return true;
+                return new ValueTask<bool>(true);
             }
 
-            await DisposeAsync().ConfigureAwait(false);
-            return false;
+            return Core();
+
+            async ValueTask<bool> Core()
+            {
+                await DisposeAsync().ConfigureAwait(false);
+                return false;
+            }
         }
 
 #if NOT_YET

+ 10 - 5
Ix.NET/Source/System.Linq.Async/System/Linq/Operators/Range.cs

@@ -107,7 +107,7 @@ namespace System.Linq
 
             public ValueTask<Maybe<int>> TryGetLastAsync(CancellationToken cancellationToken) => new ValueTask<Maybe<int>>(new Maybe<int>(_end - 1));
 
-            protected override async ValueTask<bool> MoveNextCore()
+            protected override ValueTask<bool> MoveNextCore()
             {
                 switch (_state)
                 {
@@ -115,21 +115,26 @@ namespace System.Linq
                         _current = _start;
 
                         _state = AsyncIteratorState.Iterating;
-                        return true;
+                        return new ValueTask<bool>(true);
 
                     case AsyncIteratorState.Iterating:
                         _current++;
 
                         if (_current != _end)
                         {
-                            return true;
+                            return new ValueTask<bool>(true);
                         }
 
                         break;
                 }
 
-                await DisposeAsync().ConfigureAwait(false);
-                return false;
+                return Core();
+
+                async ValueTask<bool> Core()
+                {
+                    await DisposeAsync().ConfigureAwait(false);
+                    return false;
+                }
             }
         }
     }