Browse Source

Simplify `__get_map_header` stuff

gingerBill 2 years ago
parent
commit
769d8dd038
1 changed files with 21 additions and 11 deletions
  1. 21 11
      core/runtime/dynamic_map_internal.odin

+ 21 - 11
core/runtime/dynamic_map_internal.odin

@@ -16,7 +16,7 @@ __get_map_key_hash :: #force_inline proc "contextless" (k: ^$K) -> uintptr {
 	return hasher(k, 0)
 	return hasher(k, 0)
 }
 }
 
 
-__get_map_entry_key_ptr :: #force_inline proc "contextless" (h: Map_Header, entry: ^Map_Entry_Header) -> rawptr {
+__get_map_entry_key_ptr :: #force_inline proc "contextless" (h: Map_Header_Table, entry: ^Map_Entry_Header) -> rawptr {
 	return rawptr(uintptr(entry) + h.key_offset)
 	return rawptr(uintptr(entry) + h.key_offset)
 }
 }
 
 
@@ -53,7 +53,7 @@ Map_Header_Table :: struct {
 
 
 Map_Header :: struct {
 Map_Header :: struct {
 	m: ^Raw_Map,
 	m: ^Raw_Map,
-	using header_table: Map_Header_Table,
+	using table: Map_Header_Table,
 }
 }
 
 
 // USED INTERNALLY BY THE COMPILER
 // USED INTERNALLY BY THE COMPILER
@@ -223,8 +223,19 @@ default_hasher_cstring :: proc "contextless" (data: rawptr, seed: uintptr) -> ui
 }
 }
 
 
 
 
-__get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> Map_Header {
-	header := Map_Header{m = (^Raw_Map)(m)}
+__get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> (header: Map_Header) {
+	header.m = (^Raw_Map)(m)
+	header.table = #force_inline __get_map_header_table(T)
+	return
+}
+
+__get_map_header_runtime :: proc "contextless" (m: ^Raw_Map, ti: Type_Info_Map) -> (header: Map_Header) {
+	header.m = m
+	header.table = #force_inline __get_map_header_table_runtime(ti)
+	return
+}
+
+__get_map_header_table :: proc "contextless" ($T: typeid/map[$K]$V) -> (header: Map_Header_Table) {
 	Entry :: struct {
 	Entry :: struct {
 		hash:  uintptr,
 		hash:  uintptr,
 		next:  Map_Index,
 		next:  Map_Index,
@@ -243,18 +254,16 @@ __get_map_header :: proc "contextless" (m: ^$T/map[$K]$V) -> Map_Header {
 	header.value_offset  = offset_of(Entry, value)
 	header.value_offset  = offset_of(Entry, value)
 	header.value_size    = size_of(V)
 	header.value_size    = size_of(V)
 
 
-	return header
+	return
 }
 }
 
 
-__get_map_header_runtime :: proc "contextless" (m: ^Raw_Map, ti: Type_Info_Map) -> Map_Header {
-	header := Map_Header{m = m}
-	
+__get_map_header_table_runtime :: proc "contextless" (ti: Type_Info_Map) -> (header: Map_Header) {
 	header.equal = ti.key_equal
 	header.equal = ti.key_equal
-	
+
 	entries := ti.generated_struct.variant.(Type_Info_Struct).types[1]
 	entries := ti.generated_struct.variant.(Type_Info_Struct).types[1]
 	entry := entries.variant.(Type_Info_Dynamic_Array).elem
 	entry := entries.variant.(Type_Info_Dynamic_Array).elem
 	e := entry.variant.(Type_Info_Struct)
 	e := entry.variant.(Type_Info_Struct)
-	
+
 	header.entry_size    = entry.size
 	header.entry_size    = entry.size
 	header.entry_align   = entry.align
 	header.entry_align   = entry.align
 
 
@@ -264,10 +273,11 @@ __get_map_header_runtime :: proc "contextless" (m: ^Raw_Map, ti: Type_Info_Map)
 	header.value_offset  = e.offsets[3]
 	header.value_offset  = e.offsets[3]
 	header.value_size    = e.types[3].size
 	header.value_size    = e.types[3].size
 
 
-	return header
+	return
 }
 }
 
 
 
 
+
 __slice_resize :: proc "odin" (array_: ^$T/[]$E, new_count: int, allocator: Allocator, loc := #caller_location) -> bool {
 __slice_resize :: proc "odin" (array_: ^$T/[]$E, new_count: int, allocator: Allocator, loc := #caller_location) -> bool {
 	array := (^Raw_Slice)(array_)
 	array := (^Raw_Slice)(array_)