Skip to content

Commit a0da796

Browse files
committed
Simplify code that's only used in one case.
1 parent 0bc8773 commit a0da796

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/MySqlConnector/Core/ResultSet.cs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,37 +81,32 @@ public async Task ReadResultSetHeaderAsync(IOBehavior ioBehavior)
8181
var source = hasSourcePrefix ?
8282
MySqlBulkLoader.GetAndRemoveSource(localInfile.FileName) :
8383
File.OpenRead(localInfile.FileName);
84-
85-
IDisposable? disposable = null;
86-
byte[]? buffer = null;
87-
try
84+
switch (source)
8885
{
89-
switch (source)
86+
case Stream stream:
87+
var buffer = ArrayPool<byte>.Shared.Rent(1048576);
88+
try
9089
{
91-
case Stream stream:
92-
disposable = stream;
93-
buffer = ArrayPool<byte>.Shared.Rent(1048576);
9490
int byteCount;
9591
while ((byteCount = await stream.ReadAsync(buffer, 0, buffer.Length).ConfigureAwait(false)) > 0)
9692
{
9793
payload = new PayloadData(new ArraySegment<byte>(buffer, 0, byteCount));
9894
await Session.SendReplyAsync(payload, ioBehavior, CancellationToken.None).ConfigureAwait(false);
9995
}
100-
break;
101-
102-
case MySqlBulkCopy bulkCopy:
103-
await bulkCopy.SendDataReaderAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
104-
break;
105-
106-
default:
107-
throw new InvalidOperationException("Unsupported Source type: {0}".FormatInvariant(source.GetType().Name));
10896
}
109-
}
110-
finally
111-
{
112-
if (buffer is object)
97+
finally
98+
{
11399
ArrayPool<byte>.Shared.Return(buffer);
114-
disposable?.Dispose();
100+
stream.Dispose();
101+
}
102+
break;
103+
104+
case MySqlBulkCopy bulkCopy:
105+
await bulkCopy.SendDataReaderAsync(ioBehavior, CancellationToken.None).ConfigureAwait(false);
106+
break;
107+
108+
default:
109+
throw new InvalidOperationException("Unsupported Source type: {0}".FormatInvariant(source.GetType().Name));
115110
}
116111
}
117112
catch (Exception ex)

0 commit comments

Comments
 (0)