Skip to content

Commit 404024f

Browse files
committed
Removed boxing
1 parent a17b85a commit 404024f

File tree

1 file changed

+10
-8
lines changed
  • src/DotNext/Runtime/CompilerServices

1 file changed

+10
-8
lines changed

src/DotNext/Runtime/CompilerServices/Scope.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,18 @@ static void ExecuteCallbacks(ReadOnlySpan<object?> callbacks, ref ExceptionAggre
152152
/// <returns>The task representing asynchronous execution.</returns>
153153
public readonly async ValueTask DisposeAsync()
154154
{
155-
var exceptions = BoxedValue<ExceptionAggregator>.Box(new());
156-
await ExecuteCallbacksAsync(callbacks, exceptions).ConfigureAwait(false);
155+
var exceptions = await ExecuteCallbacksAsync(callbacks).ConfigureAwait(false);
157156

158157
if (rest is not null)
159158
{
160-
await ExecuteCallbacksAsync(rest, exceptions).ConfigureAwait(false);
159+
exceptions = await ExecuteCallbacksAsync(rest, exceptions).ConfigureAwait(false);
161160
rest.Clear();
162161
}
163162

164-
exceptions.Value.ThrowIfNeeded();
163+
exceptions.ThrowIfNeeded();
165164

166-
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder))]
167-
static async ValueTask ExecuteCallbacksAsync<T>(T callbacks, BoxedValue<ExceptionAggregator> exceptions)
165+
[AsyncMethodBuilder(typeof(PoolingAsyncValueTaskMethodBuilder<>))]
166+
static async ValueTask<ExceptionAggregator> ExecuteCallbacksAsync<T>(T callbacks, ExceptionAggregator exceptions = default)
168167
where T : ITuple
169168
{
170169
for (int i = 0, count = callbacks.Length; i < count; i++)
@@ -174,7 +173,7 @@ static async ValueTask ExecuteCallbacksAsync<T>(T callbacks, BoxedValue<Exceptio
174173
switch (callbacks[i])
175174
{
176175
case null:
177-
return;
176+
goto exit;
178177
case Action callback:
179178
callback();
180179
break;
@@ -192,9 +191,12 @@ static async ValueTask ExecuteCallbacksAsync<T>(T callbacks, BoxedValue<Exceptio
192191
}
193192
catch (Exception e)
194193
{
195-
exceptions.Value.Add(e);
194+
exceptions.Add(e);
196195
}
197196
}
197+
198+
exit:
199+
return exceptions;
198200
}
199201
}
200202
}

0 commit comments

Comments
 (0)