From e5af98eabecc820a43f675fc7e57630fddb718a0 Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Thu, 9 May 2024 17:55:50 +0200 Subject: [PATCH] Simplify bitset_to_enum_slice --- core/slice/slice.odin | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/core/slice/slice.odin b/core/slice/slice.odin index 606feb22e..fff901cff 100644 --- a/core/slice/slice.odin +++ b/core/slice/slice.odin @@ -731,18 +731,9 @@ bitset_to_enum_slice_with_buffer :: proc(buf: []$E, bs: $T) -> (slice: []E) wher // sl := slice.bitset_to_enum_slice(bs) @(require_results) bitset_to_enum_slice_with_make :: proc(bs: $T, $E: typeid) -> (slice: []E) where intrinsics.type_is_enum(E), intrinsics.type_bit_set_elem_type(T) == E { - count := 0 - for _ in bs { - count += 1 - } - slice = make([]E, count) - - i := 0 - for v in bs { - slice[i] = v - i += 1 - } - return + ones := intrinsics.count_ones(transmute(E)bs) + buf := make([]E, int(ones)) + return bitset_to_enum_slice(buf, bs) } bitset_to_enum_slice :: proc{bitset_to_enum_slice_with_make, bitset_to_enum_slice_with_buffer} \ No newline at end of file