File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -853,13 +853,27 @@ impl Bindgen for FunctionBindgen<'_, '_> {
853
853
//TODO: wasm64
854
854
let align = self . interface_gen . csharp_gen . sizes . align ( element) . align_wasm32 ( ) ;
855
855
856
+ let ( array_size, element_type) = crate :: world_generator:: dotnet_aligned_array (
857
+ size,
858
+ align,
859
+ ) ;
860
+ let ret_area = self . locals . tmp ( "retArea" ) ;
861
+
856
862
self . needs_cleanup = true ;
857
863
uwrite ! (
858
864
self . src,
859
865
"
860
- var {buffer_size} = {size} * (nuint){list}.Count;
861
- var {address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
862
- cleanups.Add(()=> NativeMemory.AlignedFree({address}));
866
+ void* {address};
867
+ if (({size} * {list}.Count) < 1024) {{
868
+ var {ret_area} = stackalloc {element_type}[({array_size}*{list}.Count)+1];
869
+ {address} = (void*)(((int){ret_area}) + ({align} - 1) & -{align});
870
+ }}
871
+ else
872
+ {{
873
+ var {buffer_size} = {size} * (nuint){list}.Count;
874
+ {address} = NativeMemory.AlignedAlloc({buffer_size}, {align});
875
+ cleanups.Add(()=> NativeMemory.AlignedFree({address}));
876
+ }}
863
877
864
878
for (int {index} = 0; {index} < {list}.Count; ++{index}) {{
865
879
{ty} {block_element} = {list}[{index}];
You can’t perform that action at this time.
0 commit comments