mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 08:08:50 +00:00
Merge pull request #2887 from SentientCoffee/map-shrink-return-values
Fix a `shrink(map[T]U)` bug in the core lib
This commit is contained in:
@@ -629,7 +629,7 @@ map_reserve_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_
|
|||||||
|
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
map_shrink_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, loc := #caller_location) -> Allocator_Error {
|
map_shrink_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_Info, loc := #caller_location) -> (did_shrink: bool, err: Allocator_Error) {
|
||||||
if m.allocator.procedure == nil {
|
if m.allocator.procedure == nil {
|
||||||
m.allocator = context.allocator
|
m.allocator = context.allocator
|
||||||
}
|
}
|
||||||
@@ -639,7 +639,7 @@ map_shrink_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_I
|
|||||||
// map needs to be within the max load factor.
|
// map needs to be within the max load factor.
|
||||||
log2_capacity := map_log2_cap(m^)
|
log2_capacity := map_log2_cap(m^)
|
||||||
if uintptr(m.len) >= map_load_factor(log2_capacity - 1) {
|
if uintptr(m.len) >= map_load_factor(log2_capacity - 1) {
|
||||||
return nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
shrunk := map_alloc_dynamic(info, log2_capacity - 1, m.allocator) or_return
|
shrunk := map_alloc_dynamic(info, log2_capacity - 1, m.allocator) or_return
|
||||||
@@ -672,7 +672,7 @@ map_shrink_dynamic :: proc "odin" (#no_alias m: ^Raw_Map, #no_alias info: ^Map_I
|
|||||||
|
|
||||||
map_free_dynamic(m^, info, loc) or_return
|
map_free_dynamic(m^, info, loc) or_return
|
||||||
m.data = shrunk.data
|
m.data = shrunk.data
|
||||||
return nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
|
|||||||
Reference in New Issue
Block a user