Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing "await" prefix or "Async" suffix in "async" methods #6787

Closed
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Ryujinx.Common/Utilities/EmbeddedResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static IMemoryOwner<byte> ReadFileToRentedMemory(Assembly assembly, strin

public async static Task<byte[]> ReadAsync(Assembly assembly, string filename)
{
using var stream = GetStream(assembly, filename);
await using var stream = GetStream(assembly, filename);
if (stream == null)
{
return null;
Expand Down Expand Up @@ -97,7 +97,7 @@ public static string ReadAllText(Assembly assembly, string filename)

public async static Task<string> ReadAllTextAsync(Assembly assembly, string filename)
{
using var stream = GetStream(assembly, filename);
await using var stream = GetStream(assembly, filename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These Streams returned by GetStream() -> Assembly.GetManifestResourceStream() are based on UnmanagedMemoryStream, and disposing asynchronously only adds overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (stream == null)
{
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Ryujinx.Common/Utilities/StreamUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static IMemoryOwner<byte> StreamToRentedMemory(Stream input)

public static async Task<byte[]> StreamToBytesAsync(Stream input, CancellationToken cancellationToken = default)
{
using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
await using MemoryStream stream = MemoryStreamManager.Shared.GetStream();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no point in async-disposing of a MemoryStream, it just adds overhead around calling Dispose().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


await input.CopyToAsync(stream, cancellationToken);

Expand Down
8 changes: 4 additions & 4 deletions src/Ryujinx.Gtk3/Modules/Updater/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ private static async void InstallUpdate(UpdateDialog updateDialog, string update

if (OperatingSystem.IsLinux())
{
using Stream inStream = File.OpenRead(updateFile);
using Stream gzipStream = new GZipInputStream(inStream);
using TarInputStream tarStream = new(gzipStream, Encoding.ASCII);
await using Stream inStream = File.OpenRead(updateFile);
await using Stream gzipStream = new GZipInputStream(inStream);
await using TarInputStream tarStream = new(gzipStream, Encoding.ASCII);
updateDialog.ProgressBar.MaxValue = inStream.Length;

await Task.Run(() =>
Expand Down Expand Up @@ -429,7 +429,7 @@ private static async void InstallUpdate(UpdateDialog updateDialog, string update
}
else
{
using Stream inStream = File.OpenRead(updateFile);
await using Stream inStream = File.OpenRead(updateFile);
using ZipFile zipFile = new(inStream);
updateDialog.ProgressBar.MaxValue = zipFile.Count;

Expand Down
4 changes: 2 additions & 2 deletions src/Ryujinx.Gtk3/UI/Windows/AmiiboWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,8 @@ private async Task<string> DownloadAmiiboJson()

try
{
using FileStream dlcJsonStream = File.Create(_amiiboJsonPath, 4096, FileOptions.WriteThrough);
dlcJsonStream.Write(Encoding.UTF8.GetBytes(amiiboJsonString));
await using FileStream dlcJsonStream = File.Create(_amiiboJsonPath, 4096, FileOptions.WriteThrough);
await dlcJsonStream.WriteAsync(Encoding.UTF8.GetBytes(amiiboJsonString));
}
catch (Exception exception)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Ryujinx/UI/ViewModels/AmiiboWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ private async Task<string> DownloadAmiiboJson()

try
{
using FileStream dlcJsonStream = File.Create(_amiiboJsonPath, 4096, FileOptions.WriteThrough);
dlcJsonStream.Write(Encoding.UTF8.GetBytes(amiiboJsonString));
await using FileStream dlcJsonStream = File.Create(_amiiboJsonPath, 4096, FileOptions.WriteThrough);
await dlcJsonStream.WriteAsync(Encoding.UTF8.GetBytes(amiiboJsonString));
}
catch (Exception exception)
{
Expand Down Expand Up @@ -479,7 +479,7 @@ private async Task UpdateAmiiboPreview(string imageUrl)
if (response.IsSuccessStatusCode)
{
byte[] amiiboPreviewBytes = await response.Content.ReadAsByteArrayAsync();
using MemoryStream memoryStream = new(amiiboPreviewBytes);
await using MemoryStream memoryStream = new(amiiboPreviewBytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As noted elsewhere, async-disposing a MemoryStream only adds overhead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


Bitmap bitmap = new(memoryStream);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private async Task AddDownloadableContent(string path)
return;
}

using FileStream containerFile = File.OpenRead(path);
await using FileStream containerFile = File.OpenRead(path);

PartitionFileSystem partitionFileSystem = new();
partitionFileSystem.Initialize(containerFile.AsStorage()).ThrowIfFailure();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private async void Import_OnClick(object sender, RoutedEventArgs e)

if (result.Count > 0)
{
_profile.Image = ProcessProfileImage(File.ReadAllBytes(result[0].Path.LocalPath));
_profile.Image = ProcessProfileImage(await File.ReadAllBytesAsync(result[0].Path.LocalPath));
_parent.GoBack();
}
}
Expand Down