Skip to content

Commit

Permalink
Merge pull request #946 from adamralph/refactor
Browse files Browse the repository at this point in the history
minor refactoring
  • Loading branch information
adamralph authored Feb 11, 2024
2 parents 2212383 + 1452cc3 commit 1dbf0fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Bullseye/Internal/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public static class TaskExtensions

public static ConfiguredTaskAwaitable<TResult> Tax<TResult>(this Task<TResult> task) => task.ConfigureAwait(false);

public static bool IsAwaitable(this Task task) => !task.IsCanceled && !task.IsFaulted && !task.IsCompleted;
public static bool IsAwaitable(this Task task) => task is { IsCanceled: false, IsFaulted: false, IsCompleted: false, };
}
12 changes: 8 additions & 4 deletions Bullseye/Internal/TimeSpanExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ public static string Humanize(this TimeSpan duration)
return "0 ms";
}

var totalMilliseconds = Convert.ToInt64(duration.TotalMilliseconds);

// less than one millisecond
if (Convert.ToInt64(duration.TotalMilliseconds) < 1L)
if (totalMilliseconds < 1L)
{
return "<1 ms";
}

// milliseconds
if (Convert.ToInt64(duration.TotalMilliseconds) < 1_000L)
if (totalMilliseconds < 1_000L)
{
return duration.TotalMilliseconds.ToString("F0", provider) + " ms";
}
Expand All @@ -40,10 +42,12 @@ public static string Humanize(this TimeSpan duration)
return duration.TotalSeconds.ToString("F2", provider) + " s";
}

var totalSeconds = Convert.ToInt64(duration.TotalSeconds);

// minutes and seconds
if (Convert.ToInt64(duration.TotalSeconds) < 3600L)
if (totalSeconds < 3600L)
{
var minutes = DivRem(Convert.ToInt64(duration.TotalSeconds), 60L, out var seconds);
var minutes = DivRem(totalSeconds, 60L, out var seconds);
return seconds == 0
? $"{minutes.ToString("F0", provider)} m"
: $"{minutes.ToString("F0", provider)} m {seconds.ToString("F0", provider)} s";
Expand Down
2 changes: 1 addition & 1 deletion BullseyeSmokeTester.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using Bullseye;
using static Bullseye.Targets;

var foo = new Option<string>(new[] { "--foo", "-f", }, "A value used for something.");
var foo = new Option<string>(["--foo", "-f",], "A value used for something.");

#pragma warning disable IDE0028
var cmd = new RootCommand { foo, };
Expand Down

0 comments on commit 1dbf0fb

Please sign in to comment.