From 92222cfa19e585d52dff8a86d27b802196d5b44d Mon Sep 17 00:00:00 2001 From: Harmen Date: Wed, 14 Jan 2026 09:44:29 +0100 Subject: [PATCH] use math/bits --- cmd_string.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cmd_string.go b/cmd_string.go index 19c3543..985848c 100644 --- a/cmd_string.go +++ b/cmd_string.go @@ -4,6 +4,7 @@ package miniredis import ( "math/big" + "math/bits" "strconv" "strings" "time" @@ -1114,10 +1115,7 @@ func withRange(v string, start, end int) string { func countBits(v []byte) int { count := 0 for _, b := range []byte(v) { - for b > 0 { - count += int((b % uint8(2))) - b = b >> 1 - } + count += bits.OnesCount8(uint8(b)) } return count }