Skip to content

Commit 3d00a60

Browse files
shargoncschuchardt88nan01ab
authored
Nullable in Storage classes (neo-project#3670)
* Nullable * Optimize * Fix nullables * Fix ut * More * Update src/Neo/Persistence/DataCache.cs Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com> * Update src/Neo/Persistence/MemorySnapshot.cs Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com> * Update src/Neo/Persistence/MemoryStore.cs Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com> * Remove pragma * Clean * SnapshotCache * Change exception * Fix conflicts * Update src/Neo/Persistence/DataCache.cs Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com> * Update src/Neo/Persistence/DataCache.cs Co-authored-by: nan01ab <yjcc201374@outlook.com> * Avoid logic change --------- Co-authored-by: Christopher Schuchardt <cschuchardt88@gmail.com> Co-authored-by: nan01ab <yjcc201374@outlook.com>
1 parent 39e4fe1 commit 3d00a60

File tree

5 files changed

+139
-149
lines changed

5 files changed

+139
-149
lines changed

src/Neo/Persistence/ClonedCache.cs

+15-10
Original file line numberDiff line numberDiff line change
@@ -9,55 +9,60 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12+
#nullable enable
13+
1214
using Neo.SmartContract;
1315
using System.Collections.Generic;
1416

1517
namespace Neo.Persistence
1618
{
1719
class ClonedCache : DataCache
1820
{
19-
private readonly DataCache innerCache;
21+
private readonly DataCache _innerCache;
2022

2123
public ClonedCache(DataCache innerCache)
2224
{
23-
this.innerCache = innerCache;
25+
_innerCache = innerCache;
2426
}
2527

2628
protected override void AddInternal(StorageKey key, StorageItem value)
2729
{
28-
innerCache.Add(key, value.Clone());
30+
_innerCache.Add(key, value.Clone());
2931
}
3032

3133
protected override void DeleteInternal(StorageKey key)
3234
{
33-
innerCache.Delete(key);
35+
_innerCache.Delete(key);
3436
}
3537

3638
protected override bool ContainsInternal(StorageKey key)
3739
{
38-
return innerCache.Contains(key);
40+
return _innerCache.Contains(key);
3941
}
4042

4143
/// <inheritdoc/>
4244
protected override StorageItem GetInternal(StorageKey key)
4345
{
44-
return innerCache[key].Clone();
46+
return _innerCache[key].Clone();
4547
}
4648

4749
protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPreifx, SeekDirection direction)
4850
{
49-
foreach (var (key, value) in innerCache.Seek(keyOrPreifx, direction))
51+
foreach (var (key, value) in _innerCache.Seek(keyOrPreifx, direction))
5052
yield return (key, value.Clone());
5153
}
5254

53-
protected override StorageItem TryGetInternal(StorageKey key)
55+
protected override StorageItem? TryGetInternal(StorageKey key)
5456
{
55-
return innerCache.TryGet(key)?.Clone();
57+
return _innerCache.TryGet(key)?.Clone();
5658
}
5759

5860
protected override void UpdateInternal(StorageKey key, StorageItem value)
5961
{
60-
innerCache.GetAndChange(key).FromReplica(value);
62+
var entry = _innerCache.GetAndChange(key)
63+
?? throw new KeyNotFoundException();
64+
65+
entry.FromReplica(value);
6166
}
6267
}
6368
}

0 commit comments

Comments
 (0)