From 5b28bc2c1ab53ec5ccbce610166d2302b87dcb5e Mon Sep 17 00:00:00 2001 From: routersys Date: Sun, 13 Sep 2026 15:40:09 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=83=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=81=AE=E5=90=8C=E4=B8=80=E6=80=A7=E3=82=92=E7=AD=89=E4=BE=A1?= =?UTF-8?q?=E6=80=A7=E3=81=A8=E3=81=97=E3=81=A6=E5=AE=9A=E7=BE=A9=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProxyForge.Tests/ProxyCacheTests.cs | 13 +++++++++++++ ProxyForge/Cache/SourceIdentity.cs | 4 ++++ ProxyForge/Encoding/ProxyGenerationQueue.cs | 17 +++-------------- ProxyForge/Sources/ProxyUpgradeLoader.cs | 2 +- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/ProxyForge.Tests/ProxyCacheTests.cs b/ProxyForge.Tests/ProxyCacheTests.cs index 3fc4f1d..55c2e44 100644 --- a/ProxyForge.Tests/ProxyCacheTests.cs +++ b/ProxyForge.Tests/ProxyCacheTests.cs @@ -77,6 +77,19 @@ public sealed class ProxyCacheTests : IDisposable Assert.Equal(File.GetLastWriteTimeUtc(path).Ticks, identity.WriteTimeTicks); } + [Fact] + public void IdentitiesAreEqualRegardlessOfThePathCase() + { + var identity = new SourceIdentity(@"C:\Videos\Source.mp4", 123L, 456L); + var upper = identity with { Path = identity.Path.ToUpperInvariant() }; + + Assert.Equal(identity, upper); + Assert.Equal(identity.GetHashCode(), upper.GetHashCode()); + Assert.NotEqual(identity, identity with { Length = 124L }); + Assert.NotEqual(identity, identity with { WriteTimeTicks = 457L }); + Assert.NotEqual(identity, identity with { Path = @"C:\Videos\Other.mp4" }); + } + [Fact] public void AnEmptyCacheFindsNothing() { diff --git a/ProxyForge/Cache/SourceIdentity.cs b/ProxyForge/Cache/SourceIdentity.cs index 1448396..91dcbb5 100644 --- a/ProxyForge/Cache/SourceIdentity.cs +++ b/ProxyForge/Cache/SourceIdentity.cs @@ -27,4 +27,8 @@ internal readonly record struct SourceIdentity(string Path, long Length, long Wr => Length == length && WriteTimeTicks == writeTimeTicks && string.Equals(Path, path, StringComparison.OrdinalIgnoreCase); + + public bool Equals(SourceIdentity other) => Matches(other.Path, other.Length, other.WriteTimeTicks); + + public override int GetHashCode() => HashCode.Combine(StringComparer.OrdinalIgnoreCase.GetHashCode(Path), Length, WriteTimeTicks); } diff --git a/ProxyForge/Encoding/ProxyGenerationQueue.cs b/ProxyForge/Encoding/ProxyGenerationQueue.cs index 3f83252..8a12d10 100644 --- a/ProxyForge/Encoding/ProxyGenerationQueue.cs +++ b/ProxyForge/Encoding/ProxyGenerationQueue.cs @@ -23,25 +23,14 @@ internal sealed class ProxyGenerationQueue( readonly record struct Key(SourceIdentity Source, int Scale); - sealed class KeyComparer : IEqualityComparer - { - public static KeyComparer Instance { get; } = new(); - - public bool Equals(Key x, Key y) - => x.Scale == y.Scale && x.Source.Matches(y.Source.Path, y.Source.Length, y.Source.WriteTimeTicks); - - public int GetHashCode(Key key) - => HashCode.Combine(StringComparer.OrdinalIgnoreCase.GetHashCode(key.Source.Path), key.Source.Length, key.Source.WriteTimeTicks, key.Scale); - } - sealed class ItemProgress(ProxyGenerationItem item, Action onUi) : IProgress { public void Report(double value) => onUi(() => item.Progress = value); } readonly Lock gate = new(); - readonly Dictionary pending = new(KeyComparer.Instance); - readonly HashSet failures = new(KeyComparer.Instance); + readonly Dictionary pending = []; + readonly HashSet failures = []; readonly SemaphoreSlim slot = new(1, 1); public static ProxyGenerationQueue Shared { get; } = new( @@ -212,7 +201,7 @@ internal sealed class ProxyGenerationQueue( { result = await encode(request, new ItemProgress(item, onUi), token).ConfigureAwait(false); var latest = SourceIdentity.Of(key.Source.Path); - if (latest is null || !latest.Value.Matches(key.Source.Path, key.Source.Length, key.Source.WriteTimeTicks)) + if (latest != key.Source) throw new ProxyEncodeException(ProxyEncodeFailure.SourceChanged, "The source file changed while the proxy was being generated."); } catch diff --git a/ProxyForge/Sources/ProxyUpgradeLoader.cs b/ProxyForge/Sources/ProxyUpgradeLoader.cs index 8ff709b..d1bdc86 100644 --- a/ProxyForge/Sources/ProxyUpgradeLoader.cs +++ b/ProxyForge/Sources/ProxyUpgradeLoader.cs @@ -44,7 +44,7 @@ internal sealed class ProxyUpgradeLoader : IDisposable void OnCompleted(SourceIdentity completedSource, int completedScale, ProxyCacheEntry entry) { - if (completedScale == scale && completedSource.Matches(source.Path, source.Length, source.WriteTimeTicks)) + if (completedScale == scale && completedSource == source) Begin(entry); }