Add intrinsics.type_equal_proc; Make map use an internal equal procedure to compare keys

This commit is contained in:
gingerBill
2020-11-29 14:22:42 +00:00
parent 2e0fd34e59
commit 39bed567b3
10 changed files with 154 additions and 84 deletions
+4 -2
View File
@@ -42,6 +42,8 @@ Platform_Endianness :: enum u8 {
Big = 2,
}
Equal_Proc :: distinct proc "contextless" (rawptr, rawptr) -> bool;
Type_Info_Struct_Soa_Kind :: enum u8 {
None = 0,
Fixed = 1,
@@ -89,7 +91,6 @@ Type_Info_Tuple :: struct { // Only used for procedures parameters and results
names: []string,
};
Type_Struct_Equal_Proc :: distinct proc "contextless" (rawptr, rawptr) -> bool;
Type_Info_Struct :: struct {
types: []^Type_Info,
names: []string,
@@ -100,7 +101,7 @@ Type_Info_Struct :: struct {
is_raw_union: bool,
custom_align: bool,
equal: Type_Struct_Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set
equal: Equal_Proc, // set only when the struct has .Comparable set but does not have .Simple_Compare set
// These are only set iff this structure is an SOA structure
soa_kind: Type_Info_Struct_Soa_Kind,
@@ -351,6 +352,7 @@ Raw_Map :: struct {
entries: Raw_Dynamic_Array,
}
/////////////////////////////
// Init Startup Procedures //
/////////////////////////////
+5 -10
View File
@@ -63,13 +63,13 @@ Map_Entry_Header :: struct {
Map_Header :: struct {
m: ^Raw_Map,
is_key_string: bool,
equal: Equal_Proc,
entry_size: int,
entry_align: int,
key_offset: uintptr,
key_size: int,
key_offset: uintptr,
key_size: int,
value_offset: uintptr,
value_size: int,
@@ -115,7 +115,7 @@ __get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> Map_Header {
value: V,
};
header.is_key_string = intrinsics.type_is_string(K);
header.equal = intrinsics.type_equal_proc(K);
header.entry_size = int(size_of(Entry));
header.entry_align = int(align_of(Entry));
@@ -275,12 +275,7 @@ __dynamic_map_hash_equal :: proc(h: Map_Header, a, b: Map_Hash) -> bool {
if a.key_ptr == b.key_ptr {
return true;
}
assert(a.key_ptr != nil && b.key_ptr != nil);
if h.is_key_string {
return (^string)(a.key_ptr)^ == (^string)(b.key_ptr)^;
}
return memory_equal(a.key_ptr, b.key_ptr, h.key_size);
return h.equal(a.key_ptr, b.key_ptr);
}
return false;
}