remove some unnecessary string conversions

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2025-01-04 11:58:37 +01:00
parent a4a33d4407
commit bf0961458c
8 changed files with 11 additions and 22 deletions

View File

@@ -29,7 +29,6 @@ import (
"os"
"path/filepath"
"time"
"unsafe"
ftpserverlog "github.com/fclairamb/go-log"
"github.com/rs/zerolog"
@@ -310,7 +309,7 @@ func (l *StdLoggerWrapper) Write(p []byte) (n int, err error) {
p = p[0 : n-1]
}
Log(LevelError, l.Sender, "", "%s", bytesToString(p))
Log(LevelError, l.Sender, "", "%s", p)
return
}
@@ -390,12 +389,3 @@ func (l *LeveledLogger) With(keysAndValues ...any) ftpserverlog.Logger {
additionalKeyVals: append(l.additionalKeyVals, keysAndValues...),
}
}
func bytesToString(b []byte) string {
// unsafe.SliceData relies on cap whereas we want to rely on len
if len(b) == 0 {
return ""
}
// https://github.com/golang/go/blob/4ed358b57efdad9ed710be7f4fc51495a7620ce2/src/strings/builder.go#L41
return unsafe.String(unsafe.SliceData(b), len(b))
}