Skip to content

Commit

Permalink
Fix MemoryStore (#2759)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored May 31, 2022
1 parent bc28b21 commit 2fda404
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 36 deletions.
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);
}
}
}

0 comments on commit 2fda404

Please sign in to comment.