Skip to content

Commit 6060648

Browse files
author
Alex Kahn
committed
Reduce string allocations
1 parent af49023 commit 6060648

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎main.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ func scanRange(id int, start int64, end int64, count *atomic.Int64, wg *sync.Wai
7373
}
7474

7575
binary.BigEndian.PutUint32(b[0:4], timestamp)
76-
// TODO: Reduce allocations by replacing EncodeToString with Encode
77-
hex := hex.EncodeToString(b[:])
76+
encoded := make([]byte, 8)
77+
hex.Encode(encoded, b[:])
7878

79-
if containsLetter([]byte(hex)) {
79+
if containsLetter(encoded) {
8080
// Found an alphabetical character, skip this ID altogether
8181
passes += 1
8282
timestamp += 1
@@ -85,7 +85,7 @@ func scanRange(id int, start int64, end int64, count *atomic.Int64, wg *sync.Wai
8585

8686
// No alphabetical characters encountered
8787
if *debug {
88-
fmt.Printf("%s\t%d\t%08b\n", hex, timestamp, timestamp)
88+
fmt.Printf("%s\t%d\t%08b\n", string(encoded), timestamp, timestamp)
8989
}
9090
numericalCount += 1
9191
passes += 1

0 commit comments

Comments
 (0)