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

Commit

Permalink
Add ByteString.MaxComparableSize (#367)
Browse files Browse the repository at this point in the history
  • Loading branch information
erikzhang authored Aug 28, 2020
1 parent e3f1584 commit 1b14ec0
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit 1b14ec0

Please sign in to comment.