-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Labels
good first issueGood for newcomersGood for newcomersreference implIssues about the reference implementation of Fir, in Rust. Mainly the interpreter and the C backend.Issues about the reference implementation of Fir, in Rust. Mainly the interpreter and the C backend.
Description
Currently if I have a string "Hi" in a program this is the C we generate:
alloc_str("Hi", 2)alloc_str allocates a new memory and copies the string:
Lines 156 to 162 in d0047fc
| // Allocate string from bytes | |
| static Str alloc_str(const char* bytes, size_t len) {{ | |
| uint8_t* data = malloc(len); | |
| memcpy(data, bytes, len); | |
| Array_U8 arr = {{ .data_ptr = data, .len = len }}; | |
| return (Str){{ ._0 = arr }}; | |
| }} |
Instead of allocating a new memory we could reuse the static memory of the string literal as the data pointer here.
We should review all alloc_str calls to check whether the argument can be used as the data pointer, and whether we're properly freeing the argument after calling alloc_str.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomersreference implIssues about the reference implementation of Fir, in Rust. Mainly the interpreter and the C backend.Issues about the reference implementation of Fir, in Rust. Mainly the interpreter and the C backend.