Skip to content

Commit

Permalink
Nullable in Storage classes (neo-project#3670)
Browse files Browse the repository at this point in the history
* Nullable

* Optimize

* Fix nullables

* Fix ut

* More

* Update src/Neo/Persistence/DataCache.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

* Update src/Neo/Persistence/MemorySnapshot.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

* Update src/Neo/Persistence/MemoryStore.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

* Remove pragma

* Clean

* SnapshotCache

* Change exception

* Fix conflicts

* Update src/Neo/Persistence/DataCache.cs

Co-authored-by: Christopher Schuchardt <[email protected]>

* Update src/Neo/Persistence/DataCache.cs

Co-authored-by: nan01ab <[email protected]>

* Avoid logic change

---------

Co-authored-by: Christopher Schuchardt <[email protected]>
Co-authored-by: nan01ab <[email protected]>
  • Loading branch information
3 people authored Jan 19, 2025
1 parent 39e4fe1 commit 3d00a60
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 149 deletions.
25 changes: 15 additions & 10 deletions src/Neo/Persistence/ClonedCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,60 @@
// Redistribution and use in source and binary forms with or without
// modifications are permitted.

#nullable enable

using Neo.SmartContract;
using System.Collections.Generic;

namespace Neo.Persistence
{
class ClonedCache : DataCache
{
private readonly DataCache innerCache;
private readonly DataCache _innerCache;

public ClonedCache(DataCache innerCache)
{
this.innerCache = innerCache;
_innerCache = innerCache;
}

protected override void AddInternal(StorageKey key, StorageItem value)
{
innerCache.Add(key, value.Clone());
_innerCache.Add(key, value.Clone());
}

protected override void DeleteInternal(StorageKey key)
{
innerCache.Delete(key);
_innerCache.Delete(key);
}

protected override bool ContainsInternal(StorageKey key)
{
return innerCache.Contains(key);
return _innerCache.Contains(key);
}

/// <inheritdoc/>
protected override StorageItem GetInternal(StorageKey key)
{
return innerCache[key].Clone();
return _innerCache[key].Clone();
}

protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPreifx, SeekDirection direction)
{
foreach (var (key, value) in innerCache.Seek(keyOrPreifx, direction))
foreach (var (key, value) in _innerCache.Seek(keyOrPreifx, direction))
yield return (key, value.Clone());
}

protected override StorageItem TryGetInternal(StorageKey key)
protected override StorageItem? TryGetInternal(StorageKey key)
{
return innerCache.TryGet(key)?.Clone();
return _innerCache.TryGet(key)?.Clone();
}

protected override void UpdateInternal(StorageKey key, StorageItem value)
{
innerCache.GetAndChange(key).FromReplica(value);
var entry = _innerCache.GetAndChange(key)
?? throw new KeyNotFoundException();

entry.FromReplica(value);
}
}
}
Loading

0 comments on commit 3d00a60

Please sign in to comment.