Skip to content

Commit baa023f

Browse files
refactor: use the built-in max/min to simplify the code (#195)
Signed-off-by: shandongzhejiang <[email protected]>
1 parent 17c9d15 commit baa023f

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

crypto/batch.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ func (v *BatchVerifier) add(publicKey *Key, message, sig []byte) {
5656
// R_bytes is the first 32 bytes of the signature, but because the signature
5757
// is passed as a variable-length array it could be too short. In that case
5858
// we'll fail in Verify, so just avoid a panic here.
59-
n := 32
60-
if len(sig) < n {
61-
n = len(sig)
62-
}
59+
n := min(len(sig), 32)
6360
h.Write(sig[:n])
6461

6562
h.Write(publicKey[:])

util/base58/base58.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,7 @@ func Decode(b string) []byte {
4848
// Of course, in addition, we'll need to handle boundary condition when `b` is not multiple of 58^10.
4949
// In that case we'll use the bigRadix[n] lookup for the appropriate power.
5050
for t := b; len(t) > 0; {
51-
n := len(t)
52-
if n > 10 {
53-
n = 10
54-
}
51+
n := min(len(t), 10)
5552

5653
total := uint64(0)
5754
for _, v := range t[:n] {

0 commit comments

Comments
 (0)