Skip to content

Commit 10df3b1

Browse files
committed
Kill useless allocation
1 parent 2b2c0f8 commit 10df3b1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

LibGit2Sharp/Core/Proxy.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,13 +254,17 @@ public static void git_buf_put(IntPtr gitBufPointer, byte[] data, int offset, in
254254
{
255255
using (ThreadAffinity())
256256
{
257-
IntPtr bytesPtr = Marshal.AllocHGlobal(count);
258-
Marshal.Copy(data, offset, bytesPtr, count);
257+
unsafe
258+
{
259+
int res;
259260

260-
var res = NativeMethods.git_buf_put(gitBufPointer, bytesPtr, (UIntPtr)count);
261-
Ensure.ZeroResult(res);
261+
fixed (byte* ptr = data)
262+
{
263+
res = NativeMethods.git_buf_put(gitBufPointer, (IntPtr)ptr, (UIntPtr)count);
264+
}
262265

263-
Marshal.FreeHGlobal(bytesPtr);
266+
Ensure.ZeroResult(res);
267+
}
264268
}
265269
}
266270

0 commit comments

Comments
 (0)