From a7fb76972b5c3b80065ef09063176079580b352e Mon Sep 17 00:00:00 2001 From: Hikmatulloh Hari Mukti Date: Fri, 4 Oct 2024 17:10:49 +0700 Subject: [PATCH] chore: decoder simplify bits --- decoder/bits.go | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/decoder/bits.go b/decoder/bits.go index a67d6be2..3ee267d1 100644 --- a/decoder/bits.go +++ b/decoder/bits.go @@ -78,20 +78,13 @@ type numeric interface { // storeFromSlice creates value store from given s (slice of supported numeric type). func storeFromSlice[S []E, E numeric](s S, bitsize uint8) (store [32]uint64) { - var index uint8 - value, pos := uint64(0), uint8(0) - for { - if len(s) == 0 { - store[index] = value - break - } + var index, pos uint8 + for len(s) > 0 && index < 32 { + store[index] |= uint64(s[0]) << (pos * 8) + pos += bitsize if pos == 8 { - store[index] = value - value, pos = 0, 0 - index++ + index, pos = index+1, 0 } - value |= uint64(s[0]) << (pos * 8) - pos += bitsize s = s[1:] } return store