Skip to content

Commit 438daf0

Browse files
Merge pull request #307 from stefannikolei/stefannikolei/nullable/remove_nullable-disable
Remove nullabel disable
2 parents cd276a3 + 885e259 commit 438daf0

File tree

68 files changed

+139
-193
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+139
-193
lines changed

src/ImageSharp.Web/AsyncHelper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65

src/ImageSharp.Web/Caching/HexEncoder.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Runtime.CompilerServices;
65
using System.Runtime.InteropServices;

src/ImageSharp.Web/Caching/ICacheHash.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
namespace SixLabors.ImageSharp.Web.Caching;
65

src/ImageSharp.Web/Caching/ICacheKey.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using Microsoft.AspNetCore.Http;
65
using SixLabors.ImageSharp.Web.Commands;

src/ImageSharp.Web/Caching/IImageCache.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using SixLabors.ImageSharp.Web.Resolvers;
65

@@ -17,7 +16,7 @@ public interface IImageCache
1716
/// </summary>
1817
/// <param name="key">The cache key.</param>
1918
/// <returns>The <see cref="IImageResolver"/>.</returns>
20-
Task<IImageCacheResolver> GetAsync(string key);
19+
Task<IImageCacheResolver?> GetAsync(string key);
2120

2221
/// <summary>
2322
/// Sets the value associated with the specified key.

src/ImageSharp.Web/Caching/LegacyV1CacheKey.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Globalization;
65
using System.Text;

src/ImageSharp.Web/Caching/LruCache/ConcurrentTLruCache{TKey,TValue}.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Collections.Concurrent;
5+
using System.Diagnostics.CodeAnalysis;
66
using System.Runtime.CompilerServices;
77

88
namespace SixLabors.ImageSharp.Web.Caching;
@@ -26,6 +26,7 @@ namespace SixLabors.ImageSharp.Web.Caching;
2626
/// 6. When cold is full, cold tail is moved to warm head or removed from dictionary on depending on WasAccessed.
2727
/// </remarks>
2828
internal class ConcurrentTLruCache<TKey, TValue>
29+
where TKey : notnull
2930
{
3031
private readonly ConcurrentDictionary<TKey, LongTickCountLruItem<TKey, TValue>> dictionary;
3132

@@ -97,9 +98,9 @@ public ConcurrentTLruCache(int concurrencyLevel, int capacity, IEqualityComparer
9798
/// <param name="key">The key of the value to get.</param>
9899
/// <param name="value">When this method returns, contains the object from the cache that has the specified key, or the default value of the type if the operation failed.</param>
99100
/// <returns><see langword="true"/> if the key was found in the cache; otherwise, <see langword="false"/>.</returns>
100-
public bool TryGet(TKey key, out TValue value)
101+
public bool TryGet(TKey key, [NotNullWhen(true)] out TValue? value)
101102
{
102-
if (this.dictionary.TryGetValue(key, out LongTickCountLruItem<TKey, TValue> item))
103+
if (this.dictionary.TryGetValue(key, out LongTickCountLruItem<TKey, TValue>? item))
103104
{
104105
return this.GetOrDiscard(item, out value);
105106
}
@@ -111,7 +112,7 @@ public bool TryGet(TKey key, out TValue value)
111112
// AggressiveInlining forces the JIT to inline policy.ShouldDiscard(). For LRU policy
112113
// the first branch is completely eliminated due to JIT time constant propogation.
113114
[MethodImpl(MethodImplOptions.AggressiveInlining)]
114-
private bool GetOrDiscard(LongTickCountLruItem<TKey, TValue> item, out TValue value)
115+
private bool GetOrDiscard(LongTickCountLruItem<TKey, TValue> item, out TValue? value)
115116
{
116117
if (this.policy.ShouldDiscard(item))
117118
{
@@ -135,7 +136,7 @@ private bool GetOrDiscard(LongTickCountLruItem<TKey, TValue> item, out TValue va
135136
/// in the cache, or the new value if the key was not in the dictionary.</returns>
136137
public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
137138
{
138-
if (this.TryGet(key, out TValue value))
139+
if (this.TryGet(key, out TValue? value))
139140
{
140141
return value;
141142
}
@@ -164,7 +165,7 @@ public TValue GetOrAdd(TKey key, Func<TKey, TValue> valueFactory)
164165
/// <returns>A task that represents the asynchronous <see cref="GetOrAdd(TKey, Func{TKey, TValue})"/> operation.</returns>
165166
public async Task<TValue> GetOrAddAsync(TKey key, Func<TKey, Task<TValue>> valueFactory)
166167
{
167-
if (this.TryGet(key, out TValue value))
168+
if (this.TryGet(key, out TValue? value))
168169
{
169170
return value;
170171
}
@@ -202,7 +203,7 @@ public bool TryRemove(TKey key)
202203
// and it will not be marked as removed. If key 1 is fetched while LruItem1* is still in the queue, there will
203204
// be two queue entries for key 1, and neither is marked as removed. Thus when LruItem1 * ages out, it will
204205
// incorrectly remove 1 from the dictionary, and this cycle can repeat.
205-
if (this.dictionary.TryGetValue(key, out LongTickCountLruItem<TKey, TValue> existing))
206+
if (this.dictionary.TryGetValue(key, out LongTickCountLruItem<TKey, TValue>? existing))
206207
{
207208
if (existing.WasRemoved)
208209
{
@@ -219,7 +220,7 @@ public bool TryRemove(TKey key)
219220
existing.WasRemoved = true;
220221
}
221222

222-
if (this.dictionary.TryRemove(key, out LongTickCountLruItem<TKey, TValue> removedItem))
223+
if (this.dictionary.TryRemove(key, out LongTickCountLruItem<TKey, TValue>? removedItem))
223224
{
224225
// Mark as not accessed, it will later be cycled out of the queues because it can never be fetched
225226
// from the dictionary. Note: Hot/Warm/Cold count will reflect the removed item until it is cycled
@@ -261,7 +262,7 @@ private void CycleHot()
261262
{
262263
Interlocked.Decrement(ref this.hotCount);
263264

264-
if (this.hotQueue.TryDequeue(out LongTickCountLruItem<TKey, TValue> item))
265+
if (this.hotQueue.TryDequeue(out LongTickCountLruItem<TKey, TValue>? item))
265266
{
266267
ItemDestination where = this.policy.RouteHot(item);
267268
this.Move(item, where);
@@ -279,7 +280,7 @@ private void CycleWarm()
279280
{
280281
Interlocked.Decrement(ref this.warmCount);
281282

282-
if (this.warmQueue.TryDequeue(out LongTickCountLruItem<TKey, TValue> item))
283+
if (this.warmQueue.TryDequeue(out LongTickCountLruItem<TKey, TValue>? item))
283284
{
284285
ItemDestination where = this.policy.RouteWarm(item);
285286

@@ -308,7 +309,7 @@ private void CycleCold()
308309
{
309310
Interlocked.Decrement(ref this.coldCount);
310311

311-
if (this.coldQueue.TryDequeue(out LongTickCountLruItem<TKey, TValue> item))
312+
if (this.coldQueue.TryDequeue(out LongTickCountLruItem<TKey, TValue>? item))
312313
{
313314
ItemDestination where = this.policy.RouteCold(item);
314315

@@ -354,7 +355,7 @@ private void Move(LongTickCountLruItem<TKey, TValue> item, ItemDestination where
354355
break;
355356
}
356357

357-
if (this.dictionary.TryRemove(item.Key, out LongTickCountLruItem<TKey, TValue> removedItem))
358+
if (this.dictionary.TryRemove(item.Key, out LongTickCountLruItem<TKey, TValue>? removedItem))
358359
{
359360
item.WasRemoved = true;
360361
if (removedItem.Value is IDisposable d)

src/ImageSharp.Web/Caching/LruCache/LongTickCountLruItem{TKey,TValue}.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
namespace SixLabors.ImageSharp.Web.Caching;
65

src/ImageSharp.Web/Caching/LruCache/TLruLongTicksPolicy{TKey,TValue}.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Diagnostics;
65
using System.Runtime.CompilerServices;

src/ImageSharp.Web/Caching/PhysicalFileSystemCache.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright (c) Six Labors.
22
// Licensed under the Six Labors Split License.
3-
#nullable disable
43

54
using System.Runtime.CompilerServices;
65
using System.Runtime.InteropServices;
@@ -77,17 +76,17 @@ internal static string GetCacheRoot(PhysicalFileSystemCacheOptions cacheOptions,
7776
}
7877

7978
/// <inheritdoc/>
80-
public Task<IImageCacheResolver> GetAsync(string key)
79+
public Task<IImageCacheResolver?> GetAsync(string key)
8180
{
8281
string path = Path.Combine(this.cacheRootPath, ToFilePath(key, this.cacheFolderDepth));
8382

8483
FileInfo metaFileInfo = new(ToMetaDataFilePath(path));
8584
if (!metaFileInfo.Exists)
8685
{
87-
return Task.FromResult<IImageCacheResolver>(null);
86+
return Task.FromResult<IImageCacheResolver?>(null);
8887
}
8988

90-
return Task.FromResult<IImageCacheResolver>(new PhysicalFileSystemCacheResolver(metaFileInfo, this.formatUtilities));
89+
return Task.FromResult<IImageCacheResolver?>(new PhysicalFileSystemCacheResolver(metaFileInfo, this.formatUtilities));
9190
}
9291

9392
/// <inheritdoc/>
@@ -96,10 +95,10 @@ public async Task SetAsync(string key, Stream stream, ImageCacheMetadata metadat
9695
string path = Path.Combine(this.cacheRootPath, ToFilePath(key, this.cacheFolderDepth));
9796
string imagePath = this.ToImageFilePath(path, metadata);
9897
string metaPath = ToMetaDataFilePath(path);
99-
string directory = Path.GetDirectoryName(path);
98+
string? directory = Path.GetDirectoryName(path);
10099

101100
// Ensure cache directory is created before creating files
102-
if (!Directory.Exists(directory))
101+
if (!Directory.Exists(directory) && directory is not null)
103102
{
104103
Directory.CreateDirectory(directory);
105104
}

0 commit comments

Comments
 (0)