Skip to content

Commit 879c91c

Browse files
committed
use math/bits
1 parent dfe3831 commit 879c91c

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

cmd_string.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package miniredis
44

55
import (
66
"math/big"
7+
"math/bits"
78
"strconv"
89
"strings"
910
"time"
@@ -1114,10 +1115,7 @@ func withRange(v string, start, end int) string {
11141115
func countBits(v []byte) int {
11151116
count := 0
11161117
for _, b := range []byte(v) {
1117-
for b > 0 {
1118-
count += int((b % uint8(2)))
1119-
b = b >> 1
1120-
}
1118+
count += bits.OnesCount8(uint8(b))
11211119
}
11221120
return count
11231121
}

0 commit comments

Comments
 (0)