mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Hash maps now copy keys if keys are copyable.
This commit is contained in:
@@ -177,19 +177,14 @@ macro bool equals(a, b, isz len = -1, usz $align = 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
macro @clone(&value) @builtin
|
||||
macro @clone(&value, Allocator *using = mem::heap()) @builtin
|
||||
{
|
||||
$typeof(value)* x = malloc($typeof(value));
|
||||
$typeof(value)* x = malloc($typeof(value), .using = using);
|
||||
*x = value;
|
||||
return x;
|
||||
}
|
||||
|
||||
macro @tclone(&value) @builtin
|
||||
{
|
||||
$typeof(value)* x = talloc($typeof(value));
|
||||
*x = value;
|
||||
return x;
|
||||
}
|
||||
macro @tclone(&value) @builtin => @clone(value, mem::temp());
|
||||
|
||||
macro type_alloc_must_be_aligned($Type)
|
||||
{
|
||||
|
||||
@@ -346,6 +346,12 @@ fn String String.copy(s, Allocator* using = mem::heap())
|
||||
str[len] = 0;
|
||||
return (String)str[:len];
|
||||
}
|
||||
fn void String.free(&s, Allocator* using = mem::heap())
|
||||
{
|
||||
if (!s.len) return;
|
||||
mem::free(s.ptr, .using = using);
|
||||
*s = "";
|
||||
}
|
||||
|
||||
fn String String.tcopy(s) => s.copy(mem::temp()) @inline;
|
||||
|
||||
|
||||
@@ -229,6 +229,14 @@ macro bool is_equatable_type($Type)
|
||||
$endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a type implements the copy protocol.
|
||||
**/
|
||||
macro bool implements_copy($Type)
|
||||
{
|
||||
return $checks(Allocator *a, $Type x, $Type y = x.copy(a), $Type z = x.copy(), z.free(a), z.free());
|
||||
}
|
||||
|
||||
macro bool is_equatable_value(value)
|
||||
{
|
||||
return is_equatable_type($typeof(value));
|
||||
|
||||
Reference in New Issue
Block a user