mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-24 14:45:00 -07:00
Allow comparisons of cstring; Add resize
This commit is contained in:
@@ -394,6 +394,9 @@ clear :: proc[clear_dynamic_array, clear_map];
|
||||
@(builtin)
|
||||
reserve :: proc[reserve_dynamic_array, reserve_map];
|
||||
|
||||
@(builtin)
|
||||
resize :: proc[resize_dynamic_array];
|
||||
|
||||
|
||||
@(builtin)
|
||||
new :: proc[mem.new];
|
||||
@@ -537,6 +540,38 @@ reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #cal
|
||||
return true;
|
||||
}
|
||||
|
||||
@(builtin)
|
||||
resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller_location) -> bool {
|
||||
if array == nil do return false;
|
||||
a := (^mem.Raw_Dynamic_Array)(array);
|
||||
|
||||
if length <= a.cap {
|
||||
a.len = max(length, 0);
|
||||
return true;
|
||||
}
|
||||
|
||||
if a.allocator.procedure == nil {
|
||||
a.allocator = context.allocator;
|
||||
}
|
||||
assert(a.allocator.procedure != nil);
|
||||
|
||||
old_size := a.cap * size_of(E);
|
||||
new_size := length * size_of(E);
|
||||
allocator := a.allocator;
|
||||
|
||||
new_data := allocator.procedure(
|
||||
allocator.data, mem.Allocator_Mode.Resize, new_size, align_of(E),
|
||||
a.data, old_size, 0, loc,
|
||||
);
|
||||
if new_data == nil do return false;
|
||||
|
||||
a.data = new_data;
|
||||
a.len = length;
|
||||
a.cap = length;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@(builtin)
|
||||
incl_elem :: inline proc(s: ^$S/bit_set[$E; $U], elem: E) -> S {
|
||||
|
||||
@@ -3767,6 +3767,11 @@ irValue *ir_emit_comp(irProcedure *proc, TokenKind op_kind, irValue *left, irVal
|
||||
}
|
||||
|
||||
if (is_type_string(a)) {
|
||||
if (is_type_cstring(a)) {
|
||||
left = ir_emit_conv(proc, left, t_string);
|
||||
right = ir_emit_conv(proc, right, t_string);
|
||||
}
|
||||
|
||||
char *runtime_proc = nullptr;
|
||||
switch (op_kind) {
|
||||
case Token_CmpEq: runtime_proc = "string_eq"; break;
|
||||
|
||||
+3
-1
@@ -1238,8 +1238,10 @@ bool is_type_comparable(Type *t) {
|
||||
return false;
|
||||
case Basic_rune:
|
||||
return true;
|
||||
case Basic_string:
|
||||
return true;
|
||||
case Basic_cstring:
|
||||
return false;
|
||||
return true;
|
||||
case Basic_typeid:
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user