Skip to content

Commit 2a55686

Browse files
author
Not Officer
committed
net 5.0 performance boost
1 parent 44caae4 commit 2a55686

3 files changed

Lines changed: 28 additions & 18 deletions

File tree

src/Classes/Usmap.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,15 @@ internal Usmap(GenericReader fileReader, UsmapOptions options)
7474
fileReader.Dispose();
7575
var data = new byte[decompSize];
7676
using var decompressor = new OodleDecompressor(options.OodlePath);
77-
var result = decompressor.Decompress(compData, compSize, data, decompSize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3);
7877

79-
if (result != decompSize)
78+
unsafe
8079
{
81-
throw new FileLoadException($"Invalid oodle .usmap decompress result: {result} / {decompSize}");
80+
var result = decompressor.Decompress(compData, compSize, data, decompSize, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3);
81+
82+
if (result != decompSize)
83+
{
84+
throw new FileLoadException($"Invalid oodle .usmap decompress result: {result} / {decompSize}");
85+
}
8286
}
8387

8488
reader = new GenericBufferReader(data);

src/OodleDecompressor.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,27 @@
33

44
namespace UsmapNET
55
{
6-
internal class OodleDecompressor : IDisposable
6+
internal unsafe class OodleDecompressor : IDisposable
77
{
88
private readonly IntPtr _handle;
99

10+
#if NET5_0
11+
public readonly delegate* unmanaged[Cdecl]<byte[], long, byte[], long, int, int, int, long, long, long, long, long, long, int, long> Decompress;
12+
#else
1013
public delegate long OodleLZ_Decompress(byte[] buffer, long bufferSize, byte[] result, long outputBufferSize, int a, int b, int c, long d, long e, long f, long g, long h, long i, int ThreadModule);
1114
public readonly OodleLZ_Decompress Decompress;
15+
#endif
1216

1317
public OodleDecompressor(string oodlePath)
1418
{
1519
_handle = NativeLibrary.Load(oodlePath);
1620
var address = NativeLibrary.GetExport(_handle, "OodleLZ_Decompress");
21+
22+
#if NET5_0
23+
Decompress = (delegate* unmanaged[Cdecl]<byte[], long, byte[], long, int, int, int, long, long, long, long, long, long, int, long>)address;
24+
#else
1725
Decompress = Marshal.GetDelegateForFunctionPointer<OodleLZ_Decompress>(address);
26+
#endif
1827
}
1928

2029
public void Dispose()

src/Usmap.NET.csproj

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
@@ -12,28 +12,25 @@
1212
<RepositoryType>git</RepositoryType>
1313
<PackageTags>usmap parser</PackageTags>
1414
<NeutralLanguage>en</NeutralLanguage>
15-
<Version>1.1.0</Version>
16-
<PackageReleaseNotes>Easier oodle library usage</PackageReleaseNotes>
15+
<Version>1.1.1</Version>
16+
<PackageReleaseNotes>NET 5.0 performance boost</PackageReleaseNotes>
1717
</PropertyGroup>
1818

1919
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
20-
<PlatformTarget>x64</PlatformTarget>
20+
<PlatformTarget>x64</PlatformTarget>
21+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2122
</PropertyGroup>
2223

2324
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
24-
<PlatformTarget>x64</PlatformTarget>
25-
</PropertyGroup>
26-
27-
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|net5.0|AnyCPU'">
28-
<DebugType>portable</DebugType>
29-
<DebugSymbols>true</DebugSymbols>
25+
<PlatformTarget>x64</PlatformTarget>
26+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3027
</PropertyGroup>
3128

3229
<ItemGroup>
33-
<None Include="..\LICENSE">
34-
<Pack>True</Pack>
35-
<PackagePath></PackagePath>
36-
</None>
30+
<None Include="..\LICENSE">
31+
<Pack>True</Pack>
32+
<PackagePath></PackagePath>
33+
</None>
3734
</ItemGroup>
3835

3936
</Project>

0 commit comments

Comments
 (0)