Use a crc32 hash as a key
This commit is contained in:
parent
b2180d34bc
commit
6670961fda
1 changed files with 10 additions and 3 deletions
|
@ -5,6 +5,7 @@ using Avalonia.Media.Imaging;
|
||||||
using System;
|
using System;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.IO.Hashing;
|
||||||
using System.Runtime.Caching;
|
using System.Runtime.Caching;
|
||||||
|
|
||||||
namespace Ryujinx.Ava.UI.Helpers
|
namespace Ryujinx.Ava.UI.Helpers
|
||||||
|
@ -26,18 +27,19 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
|
|
||||||
if (value is byte[] buffer && targetType == typeof(IImage))
|
if (value is byte[] buffer && targetType == typeof(IImage))
|
||||||
{
|
{
|
||||||
var retrieved = cache.Contains(buffer.AsSpan().ToString());
|
var bufferhash = BufferHash(buffer);
|
||||||
|
var retrieved = cache.Contains(bufferhash);
|
||||||
|
|
||||||
if (retrieved == false)
|
if (retrieved == false)
|
||||||
{
|
{
|
||||||
MemoryStream mem = new(buffer);
|
MemoryStream mem = new(buffer);
|
||||||
var bitmap = new Bitmap(mem).CreateScaledBitmap(new PixelSize(256, 256));
|
var bitmap = new Bitmap(mem).CreateScaledBitmap(new PixelSize(256, 256));
|
||||||
cache.Add(buffer.AsSpan().ToString(), bitmap, policy);
|
cache.Add(bufferhash, bitmap, policy);
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return cache.Get(buffer.AsSpan().ToString());
|
return cache.Get(bufferhash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,5 +55,10 @@ namespace Ryujinx.Ava.UI.Helpers
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
}
|
}
|
||||||
|
private static string BufferHash(byte[] input)
|
||||||
|
{
|
||||||
|
var hashBytes = Crc32.HashToUInt32(input);
|
||||||
|
return hashBytes.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue