]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
all: use any in place of interface{}
authorJosh Bleecher Snyder <josh@tailscale.com>
Wed, 16 Mar 2022 23:40:24 +0000 (16:40 -0700)
committerJosh Bleecher Snyder <josh@tailscale.com>
Wed, 16 Mar 2022 23:40:24 +0000 (16:40 -0700)
Enabled by using Go 1.18. A bit less verbose.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
device/logger.go
device/pools.go
device/pools_test.go
device/uapi.go

index c79c97160ebb413f9a44ed925d3dbc5a95b2bb73..29073e92b0b72583dcda8180ecb022194a888d98 100644 (file)
@@ -16,8 +16,8 @@ import (
 // They do not require a trailing newline in the format.
 // If nil, that level of logging will be silent.
 type Logger struct {
-       Verbosef func(format string, args ...interface{})
-       Errorf   func(format string, args ...interface{})
+       Verbosef func(format string, args ...any)
+       Errorf   func(format string, args ...any)
 }
 
 // Log levels for use with NewLogger.
@@ -28,14 +28,14 @@ const (
 )
 
 // Function for use in Logger for discarding logged lines.
-func DiscardLogf(format string, args ...interface{}) {}
+func DiscardLogf(format string, args ...any) {}
 
 // NewLogger constructs a Logger that writes to stdout.
 // It logs at the specified log level and above.
 // It decorates log lines with the log level, date, time, and prepend.
 func NewLogger(level int, prepend string) *Logger {
        logger := &Logger{DiscardLogf, DiscardLogf}
-       logf := func(prefix string) func(string, ...interface{}) {
+       logf := func(prefix string) func(string, ...any) {
                return log.New(os.Stdout, prefix+": "+prepend, log.Ldate|log.Ltime).Printf
        }
        if level >= LogLevelVerbose {
index f1d1fa099c4554cf44a34a560a07839e49c94bc2..f40477b6687417609ac0233cbf07253abbf2f339 100644 (file)
@@ -18,13 +18,13 @@ type WaitPool struct {
        max   uint32
 }
 
-func NewWaitPool(max uint32, new func() interface{}) *WaitPool {
+func NewWaitPool(max uint32, new func() any) *WaitPool {
        p := &WaitPool{pool: sync.Pool{New: new}, max: max}
        p.cond = sync.Cond{L: &p.lock}
        return p
 }
 
-func (p *WaitPool) Get() interface{} {
+func (p *WaitPool) Get() any {
        if p.max != 0 {
                p.lock.Lock()
                for atomic.LoadUint32(&p.count) >= p.max {
@@ -36,7 +36,7 @@ func (p *WaitPool) Get() interface{} {
        return p.pool.Get()
 }
 
-func (p *WaitPool) Put(x interface{}) {
+func (p *WaitPool) Put(x any) {
        p.pool.Put(x)
        if p.max == 0 {
                return
@@ -46,13 +46,13 @@ func (p *WaitPool) Put(x interface{}) {
 }
 
 func (device *Device) PopulatePools() {
-       device.pool.messageBuffers = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
+       device.pool.messageBuffers = NewWaitPool(PreallocatedBuffersPerPool, func() any {
                return new([MaxMessageSize]byte)
        })
-       device.pool.inboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
+       device.pool.inboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() any {
                return new(QueueInboundElement)
        })
-       device.pool.outboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() interface{} {
+       device.pool.outboundElements = NewWaitPool(PreallocatedBuffersPerPool, func() any {
                return new(QueueOutboundElement)
        })
 }
index b0840e1fc074c946ef7fc57c882f68b32877716f..17e2298f93a2c265d0c9033a47a2426b5973b939 100644 (file)
@@ -26,7 +26,7 @@ func TestWaitPool(t *testing.T) {
        if workers-4 <= 0 {
                t.Skip("Not enough cores")
        }
-       p := NewWaitPool(uint32(workers-4), func() interface{} { return make([]byte, 16) })
+       p := NewWaitPool(uint32(workers-4), func() any { return make([]byte, 16) })
        wg.Add(workers)
        max := uint32(0)
        updateMax := func() {
@@ -71,7 +71,7 @@ func BenchmarkWaitPool(b *testing.B) {
        if workers-4 <= 0 {
                b.Skip("Not enough cores")
        }
-       p := NewWaitPool(uint32(workers-4), func() interface{} { return make([]byte, 16) })
+       p := NewWaitPool(uint32(workers-4), func() any { return make([]byte, 16) })
        wg.Add(workers)
        b.ResetTimer()
        for i := 0; i < workers; i++ {
index 746cf29eeecc039ea173c28fdfd2f12332f56f8b..30dd97e8b41679ea25d650c1baf0782ba6d79f32 100644 (file)
@@ -39,12 +39,12 @@ func (s IPCError) ErrorCode() int64 {
        return s.code
 }
 
-func ipcErrorf(code int64, msg string, args ...interface{}) *IPCError {
+func ipcErrorf(code int64, msg string, args ...any) *IPCError {
        return &IPCError{code: code, err: fmt.Errorf(msg, args...)}
 }
 
 var byteBufferPool = &sync.Pool{
-       New: func() interface{} { return new(bytes.Buffer) },
+       New: func() any { return new(bytes.Buffer) },
 }
 
 // IpcGetOperation implements the WireGuard configuration protocol "get" operation.
@@ -56,7 +56,7 @@ func (device *Device) IpcGetOperation(w io.Writer) error {
        buf := byteBufferPool.Get().(*bytes.Buffer)
        buf.Reset()
        defer byteBufferPool.Put(buf)
-       sendf := func(format string, args ...interface{}) {
+       sendf := func(format string, args ...any) {
                fmt.Fprintf(buf, format, args...)
                buf.WriteByte('\n')
        }