Skip to content

Commit 9347754

Browse files
committed
Merge branch 'remove-tarjan-v2' of https://github.com/neo-project/neo into remove-tarjan-v2
2 parents 066cc8b + 21e5434 commit 9347754

File tree

5 files changed

+63
-19
lines changed

5 files changed

+63
-19
lines changed

.github/workflows/main.yml

+11-3
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,17 @@ jobs:
6363
uses: actions/setup-dotnet@v4
6464
with:
6565
dotnet-version: ${{ env.DOTNET_VERSION }}
66-
67-
- name: Test
68-
if: matrix.os != 'ubuntu-latest'
66+
67+
- name: Test (MacOS)
68+
if: matrix.os == 'macos-latest'
69+
run: |
70+
brew install leveldb
71+
dotnet build
72+
cp -vp /opt/homebrew/Cellar/leveldb/1.23_1/lib/libleveldb.dylib ./tests/Neo.Plugins.Storage.Tests/bin/Debug/net8.0/
73+
dotnet test --blame-hang --blame-crash --no-build
74+
75+
- name: Test (windows)
76+
if: matrix.os == 'windows-latest'
6977
run: |
7078
dotnet sln neo.sln remove ./tests/Neo.Plugins.Storage.Tests/Neo.Plugins.Storage.Tests.csproj
7179
dotnet build

src/Neo.Cryptography.BLS12_381/Neo.Cryptography.BLS12_381.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="6.0.0" />
1414
</ItemGroup>
1515

16+
<ItemGroup>
17+
<ProjectReference Include="..\Neo.Extensions\Neo.Extensions.csproj" />
18+
</ItemGroup>
19+
1620
</Project>

src/Neo.Cryptography.BLS12_381/Scalar.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12+
using Neo.Extensions;
1213
using System.Diagnostics.CodeAnalysis;
1314
using System.Runtime.CompilerServices;
1415
using System.Runtime.InteropServices;
@@ -119,11 +120,11 @@ private Span<ulong> GetSpanU64()
119120

120121
public override string ToString()
121122
{
122-
byte[] bytes = ToArray();
123-
StringBuilder sb = new();
123+
var bytes = ToArray();
124+
125+
StringBuilder sb = new(2 + (bytes.Length * 2));
124126
sb.Append("0x");
125-
for (int i = bytes.Length - 1; i >= 0; i--)
126-
sb.AppendFormat("{0:x2}", bytes[i]);
127+
sb.Append(bytes.ToHexString(true));
127128
return sb.ToString();
128129
}
129130

src/Neo.Extensions/ByteExtensions.cs

+43-11
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,36 @@
1010
// modifications are permitted.
1111

1212
using System;
13+
using System.Runtime.CompilerServices;
1314
using System.Text;
1415

1516
namespace Neo.Extensions
1617
{
1718
public static class ByteExtensions
1819
{
20+
private const string s_hexChars = "0123456789abcdef";
21+
1922
/// <summary>
2023
/// Converts a byte array to hex <see cref="string"/>.
2124
/// </summary>
2225
/// <param name="value">The byte array to convert.</param>
2326
/// <returns>The converted hex <see cref="string"/>.</returns>
27+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2428
public static string ToHexString(this byte[] value)
2529
{
26-
StringBuilder sb = new();
27-
foreach (var b in value)
28-
sb.AppendFormat("{0:x2}", b);
29-
return sb.ToString();
30+
#if NET9_0_OR_GREATER
31+
return Convert.ToHexStringLower(value);
32+
#else
33+
return string.Create(value.Length * 2, value, (span, bytes) =>
34+
{
35+
for (var i = 0; i < bytes.Length; i++)
36+
{
37+
var b = bytes[i];
38+
span[i * 2] = s_hexChars[b >> 4];
39+
span[i * 2 + 1] = s_hexChars[b & 0xF];
40+
}
41+
});
42+
#endif
3043
}
3144

3245
/// <summary>
@@ -35,25 +48,44 @@ public static string ToHexString(this byte[] value)
3548
/// <param name="value">The byte array to convert.</param>
3649
/// <param name="reverse">Indicates whether it should be converted in the reversed byte order.</param>
3750
/// <returns>The converted hex <see cref="string"/>.</returns>
51+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3852
public static string ToHexString(this byte[] value, bool reverse = false)
3953
{
40-
StringBuilder sb = new();
41-
for (var i = 0; i < value.Length; i++)
42-
sb.AppendFormat("{0:x2}", value[reverse ? value.Length - i - 1 : i]);
43-
return sb.ToString();
54+
if (!reverse)
55+
return ToHexString(value);
56+
57+
return string.Create(value.Length * 2, value, (span, bytes) =>
58+
{
59+
for (var i = 0; i < bytes.Length; i++)
60+
{
61+
var b = bytes[bytes.Length - i - 1];
62+
span[i * 2] = s_hexChars[b >> 4];
63+
span[i * 2 + 1] = s_hexChars[b & 0xF];
64+
}
65+
});
4466
}
4567

4668
/// <summary>
4769
/// Converts a byte array to hex <see cref="string"/>.
4870
/// </summary>
4971
/// <param name="value">The byte array to convert.</param>
5072
/// <returns>The converted hex <see cref="string"/>.</returns>
73+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5174
public static string ToHexString(this ReadOnlySpan<byte> value)
5275
{
53-
StringBuilder sb = new();
54-
foreach (var b in value)
55-
sb.AppendFormat("{0:x2}", b);
76+
#if NET9_0_OR_GREATER
77+
return Convert.ToHexStringLower(value);
78+
#else
79+
// string.Create with ReadOnlySpan<char> not supported in NET5 or lower
80+
var sb = new StringBuilder(value.Length * 2);
81+
for (var i = 0; i < value.Length; i++)
82+
{
83+
var b = value[i];
84+
sb.Append(s_hexChars[b >> 4]);
85+
sb.Append(s_hexChars[b & 0xF]);
86+
}
5687
return sb.ToString();
88+
#endif
5789
}
5890
}
5991
}

tests/Neo.VM.Tests/UT_ReferenceCounter.cs

-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ public void TestArrayNoPush()
237237
using ExecutionEngine engine = new();
238238
engine.LoadScript(sb.ToArray());
239239
Assert.AreEqual(0, engine.ReferenceCounter.Count);
240-
241240
Array array = new(engine.ReferenceCounter, new StackItem[] { 1, 2, 3, 4 });
242241
Assert.AreEqual(array.Count, engine.ReferenceCounter.Count);
243242
Assert.AreEqual(VMState.HALT, engine.Execute());

0 commit comments

Comments
 (0)