Skip to content

Commit

Permalink
Merge pull request #1746 from turbedi/minor_cleanup
Browse files Browse the repository at this point in the history
Minor cleanups and optimizations
  • Loading branch information
d2phap committed Dec 2, 2023
2 parents e47e3dc + 34fd5fb commit a6e640b
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
14 changes: 7 additions & 7 deletions Source/Components/ImageGlass.Base/BHelper/ThemeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ public static Color ColorFromHex(string hex, bool skipAlpha = false)
if (hex.Length == 8)
{
// #RRGGBBAA
red = byte.Parse(hex.Substring(0, 2), NumberStyles.AllowHexSpecifier);
green = byte.Parse(hex.Substring(2, 2), NumberStyles.AllowHexSpecifier);
blue = byte.Parse(hex.Substring(4, 2), NumberStyles.AllowHexSpecifier);
alpha = byte.Parse(hex.Substring(6, 2), NumberStyles.AllowHexSpecifier);
red = byte.Parse(hex.AsSpan(0, 2), NumberStyles.AllowHexSpecifier);
green = byte.Parse(hex.AsSpan(2, 2), NumberStyles.AllowHexSpecifier);
blue = byte.Parse(hex.AsSpan(4, 2), NumberStyles.AllowHexSpecifier);
alpha = byte.Parse(hex.AsSpan(6, 2), NumberStyles.AllowHexSpecifier);
}
else if (hex.Length == 6)
{
// #RRGGBB
red = byte.Parse(hex.Substring(0, 2), NumberStyles.AllowHexSpecifier);
green = byte.Parse(hex.Substring(2, 2), NumberStyles.AllowHexSpecifier);
blue = byte.Parse(hex.Substring(4, 2), NumberStyles.AllowHexSpecifier);
red = byte.Parse(hex.AsSpan(0, 2), NumberStyles.AllowHexSpecifier);
green = byte.Parse(hex.AsSpan(2, 2), NumberStyles.AllowHexSpecifier);
blue = byte.Parse(hex.AsSpan(4, 2), NumberStyles.AllowHexSpecifier);
}
else if (hex.Length == 4)
{
Expand Down
5 changes: 2 additions & 3 deletions Source/Components/ImageGlass.Base/Cache/DiskCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,9 @@ public void Clear()
/// <returns>Item key.</returns>
private static string MakeKey(string key)
{
using var md5 = MD5.Create();
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes(key));
var hash = MD5.HashData(Encoding.ASCII.GetBytes(key));

return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
return Convert.ToHexString(hash).ToLowerInvariant();
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static string ExifAscii(byte[] value)
if (value == null || value.Length == 0)
return string.Empty;

var str = Encoding.ASCII.GetString(value).Trim(new char[] { '\0' });
var str = Encoding.ASCII.GetString(value).Trim('\0');

return str;
}
Expand Down
3 changes: 1 addition & 2 deletions Source/igcmd/Tools/FrmSlideshow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,7 @@ private static float RandomizeSlideshowInterval()
{
var intervalTo = Config.UseRandomIntervalForSlideshow ? Config.SlideshowIntervalTo : Config.SlideshowInterval;

var ran = new Random();
var interval = (float)(ran.NextDouble() * (intervalTo - Config.SlideshowInterval) + Config.SlideshowInterval);
var interval = (Random.Shared.NextSingle() * (intervalTo - Config.SlideshowInterval) + Config.SlideshowInterval);

return interval;
}
Expand Down

0 comments on commit a6e640b

Please sign in to comment.