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

Added extra dictionary mapping from string -> uint #62

Merged
merged 6 commits into from
Nov 16, 2018
Merged
Changes from 3 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
11 changes: 9 additions & 2 deletions src/neo-vm/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Collections.Generic;

namespace Neo.VM
{
public static class Helper
{
private static Dictionary<byte[], uint> dictionary = new Dictionary<byte[], uint>();
igormcoelho marked this conversation as resolved.
Show resolved Hide resolved

igormcoelho marked this conversation as resolved.
Show resolved Hide resolved
internal static byte[] ReadVarBytes(this BinaryReader reader, int max = 0X7fffffc7)
{
return reader.ReadBytes((int)reader.ReadVarInt((ulong)max));
Expand Down Expand Up @@ -40,10 +43,14 @@ public static uint ToInteropMethodHash(this string method)

public static uint ToInteropMethodHash(this byte[] method)
{
using (SHA256 sha = SHA256.Create())
if(!dictionary.ContainsKey(method))
{
return BitConverter.ToUInt32(sha.ComputeHash(method), 0);
using (SHA256 sha = SHA256.Create())
{
dictionary[method] = BitConverter.ToUInt32(sha.ComputeHash(method), 0);
}
}
return dictionary[method];
}

internal static void WriteVarBytes(this BinaryWriter writer, byte[] value)
Expand Down