mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Dead strip by default. Add list to_string. Fix missing check for dynamic calls.
This commit is contained in:
committed by
Christoffer Lerno
parent
4baacc7d52
commit
8eaad81800
@@ -38,6 +38,26 @@ fn void List.tinit(List* list, usz initial_capacity = 16)
|
||||
list.init(initial_capacity, mem::temp()) @inline;
|
||||
}
|
||||
|
||||
fn String List.to_string(List* list, Allocator* using = mem::heap()) @dynamic
|
||||
{
|
||||
if (!list.size) return "[]".copy(using);
|
||||
if (list.size == 1) return string::printf("[%s]", list.entries[0], .using = using);
|
||||
|
||||
@stack_mem(512 + 128; Allocator* mem)
|
||||
{
|
||||
DString str;
|
||||
str.init(512, mem);
|
||||
str.append("[");
|
||||
foreach (i, element : list.entries[:list.size])
|
||||
{
|
||||
if (i != 0) str.append(", ");
|
||||
str.printf("%s", element);
|
||||
}
|
||||
str.printf("]");
|
||||
return str.copy_str(using);
|
||||
};
|
||||
}
|
||||
|
||||
fn void List.push(List* list, Type element) @inline
|
||||
{
|
||||
list.append(element);
|
||||
|
||||
Reference in New Issue
Block a user