Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MemoryStore #2759

Merged
merged 3 commits into from
May 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions src/neo/Persistence/Helper.cs

This file was deleted.

14 changes: 7 additions & 7 deletions src/neo/Persistence/MemorySnapshot.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2015-2021 The Neo Project.
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
Expand Down Expand Up @@ -40,7 +40,7 @@ public void Commit()

public void Delete(byte[] key)
{
writeBatch[key.EnsureNotNull()] = null;
writeBatch[key] = null;
}

public void Dispose()
Expand All @@ -49,7 +49,7 @@ public void Dispose()

public void Put(byte[] key, byte[] value)
{
writeBatch[key.EnsureNotNull()] = value;
writeBatch[key[..]] = value[..];
}

public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
Expand All @@ -59,18 +59,18 @@ public void Put(byte[] key, byte[] value)
if (keyOrPrefix?.Length > 0)
records = records.Where(p => comparer.Compare(p.Key, keyOrPrefix) >= 0);
records = records.OrderBy(p => p.Key, comparer);
return records.Select(p => (p.Key, p.Value));
return records.Select(p => (p.Key[..], p.Value[..]));
}

public byte[] TryGet(byte[] key)
{
immutableData.TryGetValue(key.EnsureNotNull(), out byte[] value);
return value;
immutableData.TryGetValue(key, out byte[] value);
return value?[..];
}

public bool Contains(byte[] key)
{
return innerData.ContainsKey(key.EnsureNotNull());
return immutableData.ContainsKey(key);
}
}
}
14 changes: 7 additions & 7 deletions src/neo/Persistence/MemoryStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2015-2021 The Neo Project.
// Copyright (C) 2015-2022 The Neo Project.
//
// The neo is free software distributed under the MIT software license,
// see the accompanying file LICENSE in the main directory of the
Expand All @@ -24,7 +24,7 @@ public class MemoryStore : IStore

public void Delete(byte[] key)
{
innerData.TryRemove(key.EnsureNotNull(), out _);
innerData.TryRemove(key, out _);
}

public void Dispose()
Expand All @@ -38,7 +38,7 @@ public ISnapshot GetSnapshot()

public void Put(byte[] key, byte[] value)
{
innerData[key.EnsureNotNull()] = value;
innerData[key[..]] = value[..];
}

public IEnumerable<(byte[] Key, byte[] Value)> Seek(byte[] keyOrPrefix, SeekDirection direction = SeekDirection.Forward)
Expand All @@ -51,18 +51,18 @@ public void Put(byte[] key, byte[] value)
records = records.Where(p => comparer.Compare(p.Key, keyOrPrefix) >= 0);
records = records.OrderBy(p => p.Key, comparer);
foreach (var pair in records)
yield return (pair.Key, pair.Value);
yield return (pair.Key[..], pair.Value[..]);
}

public byte[] TryGet(byte[] key)
{
innerData.TryGetValue(key.EnsureNotNull(), out byte[] value);
return value;
innerData.TryGetValue(key, out byte[] value);
return value?[..];
}

public bool Contains(byte[] key)
{
return innerData.ContainsKey(key.EnsureNotNull());
return innerData.ContainsKey(key);
}
}
}