/
lazy.go
42 lines (33 loc) · 953 Bytes
/
lazy.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package log
import (
"fmt"
cmtbytes "github.com/cometbft/cometbft/libs/bytes"
)
type LazySprintf struct {
format string
args []interface{}
}
// NewLazySprintf defers fmt.Sprintf until the Stringer interface is invoked.
// This is particularly useful for avoiding calling Sprintf when debugging is not
// active.
func NewLazySprintf(format string, args ...interface{}) *LazySprintf {
return &LazySprintf{format, args}
}
func (l *LazySprintf) String() string {
return fmt.Sprintf(l.format, l.args...)
}
type LazyBlockHash struct {
block hashable
}
type hashable interface {
Hash() cmtbytes.HexBytes
}
// NewLazyBlockHash defers block Hash until the Stringer interface is invoked.
// This is particularly useful for avoiding calling Sprintf when debugging is not
// active.
func NewLazyBlockHash(block hashable) *LazyBlockHash {
return &LazyBlockHash{block}
}
func (l *LazyBlockHash) String() string {
return l.block.Hash().String()
}