From a6ec8f85a6ae380e4c12124d679d17246930eccc Mon Sep 17 00:00:00 2001 From: Peter Huene Date: Mon, 24 Feb 2020 18:26:26 -0800 Subject: [PATCH] Loop the array of strings only once. Remove unnecessary loop when marshaling lists of strings as pointers to UTF-8 bytes. --- crates/misc/dotnet/src/Interop.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/crates/misc/dotnet/src/Interop.cs b/crates/misc/dotnet/src/Interop.cs index 55e15b563c..daa15b41a3 100644 --- a/crates/misc/dotnet/src/Interop.cs +++ b/crates/misc/dotnet/src/Interop.cs @@ -496,17 +496,13 @@ namespace Wasmtime // See: https://github.com/dotnet/runtime/issues/7315 // Therefore, we need to marshal the strings manually var handles = new GCHandle[strings.Count]; + var ptrs = new byte*[strings.Count]; for (int i = 0; i < strings.Count; ++i) { handles[i] = GCHandle.Alloc( Encoding.UTF8.GetBytes(strings[i] + '\0'), GCHandleType.Pinned ); - } - - var ptrs = new byte*[strings.Count]; - for (int i = 0; i < strings.Count; ++i) - { ptrs[i] = (byte*)handles[i].AddrOfPinnedObject(); }