aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2017-12-21 20:59:23 +0000
committergingerBill <bill@gingerbill.org>2017-12-21 20:59:23 +0000
commitac277a1cce7b42e0e7d6ff9147a2ef4efc7ca541 (patch)
treed2335f6188886d9b12360190d4f4154b4cad44c6 /core
parenta17310a83c14d708a129559c90610a7a51a147a1 (diff)
Revert `map` to be a value type and not a reference type
(Implement code for "const ref" parameters)
Diffstat (limited to 'core')
-rw-r--r--core/_preload.odin35
-rw-r--r--core/fmt.odin5
-rw-r--r--core/raw.odin7
3 files changed, 7 insertions, 40 deletions
diff --git a/core/_preload.odin b/core/_preload.odin
index e0dd616b3..6fa59aa39 100644
--- a/core/_preload.odin
+++ b/core/_preload.odin
@@ -36,8 +36,7 @@ Calling_Convention :: enum {
Type_Info_Enum_Value :: union {
rune,
i8, i16, i32, i64, i128, int,
- u8, u16, u32, u64, u128, uint,
- uintptr,
+ u8, u16, u32, u64, u128, uint, uintptr,
f32, f64,
};
@@ -915,36 +914,13 @@ __default_hash :: proc(data: []byte) -> u128 {
}
__default_hash_string :: proc(s: string) -> u128 do return __default_hash(cast([]byte)s);
-__dynamic_map_check_init :: proc(h: __Map_Header) {
- if h.m.internal == nil {
- h.m.internal = new(raw.Map_Internal);
- }
-}
-
-__dynamic_map_len :: inline proc "contextless" (p: rawptr) -> int {
- if m := transmute(raw.Map)p; m.internal != nil {
- return m.internal.entries.len;
- }
- return 0;
-}
-
-__dynamic_map_cap :: inline proc "contextless" (p: rawptr) -> int {
- if m := transmute(raw.Map)p; m.internal != nil {
- return m.internal.entries.cap;
- }
- return 0;
-}
-
__dynamic_map_reserve :: proc(using header: __Map_Header, cap: int, loc := #caller_location) {
- __dynamic_map_check_init(header);
__dynamic_array_reserve(&m.hashes, size_of(int), align_of(int), cap, loc);
__dynamic_array_reserve(&m.entries, entry_size, entry_align, cap, loc);
}
__dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int, loc := #caller_location) {
- __dynamic_map_check_init(header);
new_header: __Map_Header = header;
nm: raw.Map;
- nm.internal = new(raw.Map_Internal);
new_header.m = &nm;
header_hashes := cast(^raw.Dynamic_Array)&header.m.hashes;
@@ -982,7 +958,6 @@ __dynamic_map_rehash :: proc(using header: __Map_Header, new_count: int, loc :=
}
__dynamic_map_get :: proc(h: __Map_Header, key: __Map_Key) -> rawptr {
- __dynamic_map_check_init(h);
index := __dynamic_map_find(h, key).entry_index;
if index >= 0 {
data := cast(^byte)__dynamic_map_get_entry(h, index);
@@ -992,7 +967,6 @@ __dynamic_map_get :: proc(h: __Map_Header, key: __Map_Key) -> rawptr {
}
__dynamic_map_set :: proc(h: __Map_Header, key: __Map_Key, value: rawptr, loc := #caller_location) {
- __dynamic_map_check_init(h);
index: int;
assert(value != nil);
@@ -1028,13 +1002,11 @@ __dynamic_map_set :: proc(h: __Map_Header, key: __Map_Key, value: rawptr, loc :=
__dynamic_map_grow :: proc(using h: __Map_Header, loc := #caller_location) {
- __dynamic_map_check_init(h);
new_count := max(2*m.entries.cap + 8, __INITIAL_MAP_CAP);
__dynamic_map_rehash(h, new_count, loc);
}
__dynamic_map_full :: inline proc(using h: __Map_Header) -> bool {
- __dynamic_map_check_init(h);
return int(0.75 * f64(len(m.hashes))) <= m.entries.cap;
}
@@ -1048,7 +1020,6 @@ __dynamic_map_hash_equal :: proc(h: __Map_Header, a, b: __Map_Key) -> bool {
}
__dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_Result {
- __dynamic_map_check_init(h);
fr := __Map_Find_Result{-1, -1, -1};
if len(m.hashes) > 0 {
fr.hash_index = int(key.hash % u128(len(m.hashes)));
@@ -1064,7 +1035,6 @@ __dynamic_map_find :: proc(using h: __Map_Header, key: __Map_Key) -> __Map_Find_
}
__dynamic_map_add_entry :: proc(using h: __Map_Header, key: __Map_Key, loc := #caller_location) -> int {
- __dynamic_map_check_init(h);
prev := m.entries.len;
c := __dynamic_array_append_nothing(&m.entries, entry_size, entry_align, loc);
if c != prev {
@@ -1076,7 +1046,6 @@ __dynamic_map_add_entry :: proc(using h: __Map_Header, key: __Map_Key, loc := #c
}
__dynamic_map_delete :: proc(using h: __Map_Header, key: __Map_Key) {
- __dynamic_map_check_init(h);
fr := __dynamic_map_find(h, key);
if fr.entry_index >= 0 {
__dynamic_map_erase(h, fr);
@@ -1084,13 +1053,11 @@ __dynamic_map_delete :: proc(using h: __Map_Header, key: __Map_Key) {
}
__dynamic_map_get_entry :: proc(using h: __Map_Header, index: int) -> ^__Map_Entry_Header {
- __dynamic_map_check_init(h);
assert(0 <= index && index < m.entries.len);
return cast(^__Map_Entry_Header)(cast(^byte)m.entries.data + index*entry_size);
}
__dynamic_map_erase :: proc(using h: __Map_Header, fr: __Map_Find_Result) {
- __dynamic_map_check_init(h);
if fr.entry_prev < 0 {
m.hashes[fr.hash_index] = __dynamic_map_get_entry(h, fr.entry_index).next;
} else {
diff --git a/core/fmt.odin b/core/fmt.odin
index 81e067282..1ca26855c 100644
--- a/core/fmt.odin
+++ b/core/fmt.odin
@@ -815,8 +815,9 @@ fmt_value :: proc(fi: ^Fmt_Info, v: any, verb: rune) {
write_string(fi.buf, "map[");
defer write_byte(fi.buf, ']');
- if (^raw.Map)(v.data).internal != nil {
- entries := &(^raw.Map)(v.data).entries;
+ m := (^raw.Map)(v.data);
+ if m != nil {
+ entries := &m.entries;
gs := type_info_base(info.generated_struct).variant.(Type_Info_Struct);
ed := type_info_base(gs.types[1]).variant.(Type_Info_Dynamic_Array);
entry_type := ed.elem.variant.(Type_Info_Struct);
diff --git a/core/raw.odin b/core/raw.odin
index cfa072f99..9a9f9a77b 100644
--- a/core/raw.odin
+++ b/core/raw.odin
@@ -20,14 +20,11 @@ Dynamic_Array :: struct {
allocator: Allocator,
}
-Map_Internal :: struct {
+Map :: struct {
hashes: [dynamic]int,
entries: Dynamic_Array,
}
-Map :: struct {
- using internal: ^Map_Internal,
-}
make_any :: inline proc(data: rawptr, type_info: ^Type_Info) -> any {
return transmute(any)Any{data, type_info};
@@ -44,3 +41,5 @@ dynamic_array_data :: inline proc(a: $T/[dynamic]$E) -> ^E {
}
data :: proc[string_data, slice_data, dynamic_array_data];
+
+