Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c#: Remove Copy of data during import call for base types #1122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions crates/csharp/src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -581,21 +581,22 @@ impl Bindgen for FunctionBindgen<'_, '_> {
}

Instruction::ListCanonLower { element, realloc } => {
let list = &operands[0];
let list: &String = &operands[0];
let (_size, ty) = list_element_info(element);

match self.interface_gen.direction {
Direction::Import => {
let buffer: String = self.locals.tmp("buffer");
let buffer: String = self.locals.tmp("bufferPtr");
uwrite!(
self.src,
"
void* {buffer} = stackalloc {ty}[({list}).Length];
{list}.AsSpan<{ty}>().CopyTo(new Span<{ty}>({buffer}, {list}.Length));
fixed ({ty}* {buffer} = new ReadOnlyMemory<{ty}>({list}).Span)
{{
"
);
results.push(format!("(int){buffer}"));
results.push(format!("(nint){buffer}"));
results.push(format!("({list}).Length"));
self.fixed = self.fixed + 1;
}
Direction::Export => {
let address = self.locals.tmp("address");
Expand Down Expand Up @@ -973,11 +974,11 @@ impl Bindgen for FunctionBindgen<'_, '_> {
uwriteln!(self.src, "return ({results});")
}
}
}

// Close all the fixed blocks.
for _ in 0..self.fixed {
uwriteln!(self.src, "}}");
}
// Close all the fixed blocks.
for _ in 0..self.fixed {
uwriteln!(self.src, "}}");
}
}

Expand Down Expand Up @@ -1063,7 +1064,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {

match direction {
Direction::Import => {
let import_name = self.interface_gen.type_name_with_qualifier(&Type::Id(id), true);
let import_name = self.interface_gen.type_name_with_qualifier(&Type::Id(id), true);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some how these two lines had tabs, while rest of the file was spaces


if let FunctionKind::Constructor(_) = self.kind {
resource = "this".to_owned();
Expand All @@ -1082,13 +1083,13 @@ impl Bindgen for FunctionBindgen<'_, '_> {
Direction::Export => {
self.interface_gen.csharp_gen.needs_rep_table = true;

let export_name = self.interface_gen.csharp_gen.all_resources[&id].export_impl_name();
let export_name = self.interface_gen.csharp_gen.all_resources[&id].export_impl_name();
if is_own {
uwriteln!(
self.src,
"var {resource} = ({export_name}) {export_name}.repTable.Get\
({export_name}.WasmInterop.wasmImportResourceRep({op}));
{resource}.Handle = {op};"
({export_name}.WasmInterop.wasmImportResourceRep({op}));
{resource}.Handle = {op};"
);
} else {
uwriteln!(self.src, "var {resource} = ({export_name}) {export_name}.repTable.Get({op});");
Expand Down
Loading