Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Add ByteString.MaxComparableSize #367

Merged
merged 2 commits into from
Aug 28, 2020
Merged
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
10 changes: 8 additions & 2 deletions src/neo-vm/Types/ByteString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ namespace Neo.VM.Types
[DebuggerDisplay("Type={GetType().Name}, Value={System.BitConverter.ToString(Memory.ToArray()).Replace(\"-\", string.Empty)}")]
public class ByteString : PrimitiveType
{
public const int MaxComparableSize = ushort.MaxValue;

public static readonly ByteString Empty = ReadOnlyMemory<byte>.Empty;

internal override ReadOnlyMemory<byte> Memory { get; }
Expand All @@ -20,9 +22,13 @@ public ByteString(ReadOnlyMemory<byte> value)

public override bool Equals(StackItem other)
{
if (Size > MaxComparableSize)
throw new InvalidOperationException("The operand exceeds the maximum comparable size.");
if (ReferenceEquals(this, other)) return true;
if (other is ByteString b) return GetSpan().SequenceEqual(b.GetSpan());
return false;
if (!(other is ByteString b)) return false;
if (b.Size > MaxComparableSize)
throw new InvalidOperationException("The operand exceeds the maximum comparable size.");
return GetSpan().SequenceEqual(b.GetSpan());
}

public override bool GetBoolean()
Expand Down