Skip to content

Commit b9dd4f7

Browse files
committed
Modernize project and improve functionality
Updated Hexa.NET.Utilities.csproj to target net9.0, added AOT compatibility, and enhanced package metadata (e.g., authors, copyright, icon). Refactored Utf8Formatter.cs for cleaner UTF-8 encoding logic. Replaced benchmarking in Program.cs with a new test loop for HashMap validation.
1 parent 8bd98d7 commit b9dd4f7

File tree

4 files changed

+36
-37
lines changed

4 files changed

+36
-37
lines changed

Hexa.NET.Utilities/Hexa.NET.Utilities.csproj

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,27 @@
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
77
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8-
<LangVersion>12</LangVersion>
9-
10-
</PropertyGroup>
11-
12-
<PropertyGroup Condition="'$(TargetFramework)' == 'net8.0'">
8+
9+
<LangVersion>13</LangVersion>
10+
1311
<IsAotCompatible>true</IsAotCompatible>
1412
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
1513
<EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
1614
<EnableAotAnalyzer>true</EnableAotAnalyzer>
17-
</PropertyGroup>
18-
19-
<PropertyGroup>
15+
2016
<PackageId>Hexa.NET.Utilities</PackageId>
2117
<AssemblyVersion>1.0.0</AssemblyVersion>
22-
<PackageVersion>2.2.3</PackageVersion>
23-
<Authors>Juna</Authors>
24-
<AssemblyName>Hexa.NET.Utilities</AssemblyName>
18+
<PackageVersion>2.2.4</PackageVersion>
19+
<Description>The utilities library for HexaEngine.</Description>
20+
<PackageTags>HexaEngine Hexa HexaGen C# .NET DotNet Sharp Windows macOS Native</PackageTags>
21+
<Authors>Juna Meinhold</Authors>
22+
<Copyright>Copyright (c) 2024 Juna Meinhold</Copyright>
2523
<PackageProjectUrl>https://github.com/HexaEngine/Hexa.NET.Utilities</PackageProjectUrl>
2624
<RepositoryUrl>https://github.com/HexaEngine/Hexa.NET.Utilities</RepositoryUrl>
2725
<RepositoryType>git</RepositoryType>
28-
<Description>The utilities library for HexaEngine.</Description>
29-
<PackageTags>HexaEngine Hexa HexaGen C# .NET DotNet Sharp Windows macOS Native</PackageTags>
3026
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
3127
<PackageReadmeFile>README.md</PackageReadmeFile>
28+
<PackageIcon>icon.png</PackageIcon>
3229

3330
<GenerateDocumentationFile>true</GenerateDocumentationFile>
3431
<NoWarn>$(NoWarn);1591</NoWarn>
@@ -37,8 +34,9 @@
3734
</PropertyGroup>
3835

3936
<ItemGroup>
40-
<Content Include="../LICENSE.txt" Pack="true" PackagePath="\" />
41-
<Content Include="../README.md" Pack="true" PackagePath="\" />
37+
<None Include="../LICENSE.txt" Pack="true" PackagePath="\" />
38+
<None Include="../README.md" Pack="true" PackagePath="\" />
39+
<None Include="..\icon.png" Pack="true" PackagePath="\" />
4240
</ItemGroup>
4341

4442
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'netstandard2.0'">

Hexa.NET.Utilities/Text/Utf8Formatter.cs

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Text;
88

99
#if NET5_0_OR_GREATER
10+
1011
/// <summary>
1112
/// Helper class to work with the hidden C# Feature TypedReference.
1213
/// </summary>
@@ -1045,19 +1046,16 @@ public static unsafe int ConvertUtf16ToUtf8(char* utf16Chars, int utf16Length, b
10451046
switch (codePoint)
10461047
{
10471048
case <= 0x7F:
1048-
*utf8Bytes = (byte)codePoint;
1049-
utf8Bytes++;
1049+
*utf8Bytes++ = (byte)codePoint;
10501050
break;
10511051

10521052
case <= 0x7FF:
10531053
// 2-byte UTF-8
10541054
if (utf8Bytes + 1 >= utf8BytesEnd)
10551055
return 0;
10561056

1057-
*utf8Bytes = (byte)(0xC0 | (codePoint >> 6));
1058-
utf8Bytes++;
1059-
*utf8Bytes = (byte)(0x80 | (codePoint & 0x3F));
1060-
utf8Bytes++;
1057+
*utf8Bytes++ = (byte)(0xC0 | (codePoint >> 6));
1058+
*utf8Bytes++ = (byte)(0x80 | (codePoint & 0x3F));
10611059
break;
10621060

10631061
case >= 0xD800 and <= 0xDBFF:
@@ -1073,14 +1071,10 @@ public static unsafe int ConvertUtf16ToUtf8(char* utf16Chars, int utf16Length, b
10731071
if (utf8Bytes + 3 >= utf8BytesEnd)
10741072
return 0;
10751073

1076-
*utf8Bytes = (byte)(0xF0 | (codePointSurrogate >> 18));
1077-
utf8Bytes++;
1078-
*utf8Bytes = (byte)(0x80 | ((codePointSurrogate >> 12) & 0x3F));
1079-
utf8Bytes++;
1080-
*utf8Bytes = (byte)(0x80 | ((codePointSurrogate >> 6) & 0x3F));
1081-
utf8Bytes++;
1082-
*utf8Bytes = (byte)(0x80 | (codePointSurrogate & 0x3F));
1083-
utf8Bytes++;
1074+
*utf8Bytes++ = (byte)(0xF0 | (codePointSurrogate >> 18));
1075+
*utf8Bytes++ = (byte)(0x80 | ((codePointSurrogate >> 12) & 0x3F));
1076+
*utf8Bytes++ = (byte)(0x80 | ((codePointSurrogate >> 6) & 0x3F));
1077+
*utf8Bytes++ = (byte)(0x80 | (codePointSurrogate & 0x3F));
10841078

10851079
// Skip the low surrogate as it has already been processed
10861080
i++;
@@ -1095,12 +1089,9 @@ public static unsafe int ConvertUtf16ToUtf8(char* utf16Chars, int utf16Length, b
10951089
if (utf8Bytes + 2 >= utf8BytesEnd)
10961090
return 0;
10971091

1098-
*utf8Bytes = (byte)(0xE0 | (codePoint >> 12));
1099-
utf8Bytes++;
1100-
*utf8Bytes = (byte)(0x80 | ((codePoint >> 6) & 0x3F));
1101-
utf8Bytes++;
1102-
*utf8Bytes = (byte)(0x80 | (codePoint & 0x3F));
1103-
utf8Bytes++;
1092+
*utf8Bytes++ = (byte)(0xE0 | (codePoint >> 12));
1093+
*utf8Bytes++ = (byte)(0x80 | ((codePoint >> 6) & 0x3F));
1094+
*utf8Bytes++ = (byte)(0x80 | (codePoint & 0x3F));
11041095
break;
11051096
}
11061097
}
@@ -1876,4 +1867,4 @@ private static unsafe int CountAhead(char** format, char* formatEnd, char target
18761867
return count;
18771868
}
18781869
}
1879-
}
1870+
}

TestApp/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@ public class Program
88
{
99
private static unsafe void Main(string[] args)
1010
{
11-
var summary = BenchmarkRunner.Run<UnsafeDictionaryBenchmark>();
11+
HashMap<int, int> map = default;
12+
for (int j = 0; j < 100; ++j)
13+
{
14+
for (int i = 0; i < 1000000; ++i)
15+
{
16+
map.Add(i, 2);
17+
}
18+
map.Clear();
19+
}
20+
map.Release();
21+
//var summary = BenchmarkRunner.Run<UnsafeDictionaryBenchmark>();
1222
//var summary = BenchmarkRunner.Run<UnsafeListBenchmark>();
1323
/*
1424
UnsafeDictionaryBenchmark benchmark = new();

icon.png

201 KB
Loading

0 commit comments

Comments
 (0)