Loop the array of strings only once.
Remove unnecessary loop when marshaling lists of strings as pointers to UTF-8 bytes.
This commit is contained in:
@@ -496,17 +496,13 @@ namespace Wasmtime
|
|||||||
// See: https://github.com/dotnet/runtime/issues/7315
|
// See: https://github.com/dotnet/runtime/issues/7315
|
||||||
// Therefore, we need to marshal the strings manually
|
// Therefore, we need to marshal the strings manually
|
||||||
var handles = new GCHandle[strings.Count];
|
var handles = new GCHandle[strings.Count];
|
||||||
|
var ptrs = new byte*[strings.Count];
|
||||||
for (int i = 0; i < strings.Count; ++i)
|
for (int i = 0; i < strings.Count; ++i)
|
||||||
{
|
{
|
||||||
handles[i] = GCHandle.Alloc(
|
handles[i] = GCHandle.Alloc(
|
||||||
Encoding.UTF8.GetBytes(strings[i] + '\0'),
|
Encoding.UTF8.GetBytes(strings[i] + '\0'),
|
||||||
GCHandleType.Pinned
|
GCHandleType.Pinned
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
var ptrs = new byte*[strings.Count];
|
|
||||||
for (int i = 0; i < strings.Count; ++i)
|
|
||||||
{
|
|
||||||
ptrs[i] = (byte*)handles[i].AddrOfPinnedObject();
|
ptrs[i] = (byte*)handles[i].AddrOfPinnedObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user