summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-kv
diff options
context:
space:
mode:
authorLibravatar kim <grufwub@gmail.com>2025-08-21 16:41:50 +0200
committerLibravatar kim <gruf@noreply.codeberg.org>2025-08-21 16:41:50 +0200
commita79f83cbded3fb1165b338ce316dc9f2217467ff (patch)
tree4b4a2b7084aced51c0a691cee6352b4ecae90df8 /vendor/codeberg.org/gruf/go-kv
parent[chore] bump golangci-lint version in CI, disable var-naming package name che... (diff)
downloadgotosocial-a79f83cbded3fb1165b338ce316dc9f2217467ff.tar.xz
[chore] update dependencies (#4386)
- codeberg.org/gruf/go-bytesize v1.0.3 -> v1.0.4 - codeberg.org/gruf/go-kv/v2 v2.0.6 -> v2.0.7 - codeberg.org/gruf/go-mutexes v1.5.2 -> v1.5.3 - codeberg.org/gruf/go-structr v0.9.7 -> v0.9.8 - codeberg.org/gruf/go-ffmpreg v0.6.8 -> v0.6.9 - github.com/tomnomnom/linkheader HEAD@2018 -> HEAD@2025 all of the above codeberg.org/gruf updates are in preparation for Go1.25, except for bytesize, and also ffmpreg which is a rebuild with the latest version of ffmpeg (v5.1.7) Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4386 Co-authored-by: kim <grufwub@gmail.com> Co-committed-by: kim <grufwub@gmail.com>
Diffstat (limited to 'vendor/codeberg.org/gruf/go-kv')
-rw-r--r--vendor/codeberg.org/gruf/go-kv/v2/format/README.md32
-rw-r--r--vendor/codeberg.org/gruf/go-kv/v2/format/methods.go54
2 files changed, 74 insertions, 12 deletions
diff --git a/vendor/codeberg.org/gruf/go-kv/v2/format/README.md b/vendor/codeberg.org/gruf/go-kv/v2/format/README.md
new file mode 100644
index 000000000..5d11cc6b9
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-kv/v2/format/README.md
@@ -0,0 +1,32 @@
+# format
+
+a low-level string formatting library that takes arbitrary input types as interfaces, and arguments as a struct. this does not contain any printf-like argument parsing, only log-friendly serialization of arbitrary input arguments. (noting that our output is noticably more log-friendly for struct / map types than stdlib "fmt").
+
+benchmarks:
+```shell
+goos: linux
+goarch: amd64
+pkg: codeberg.org/gruf/go-kv/v2/format
+cpu: AMD Ryzen 7 7840U w/ Radeon 780M Graphics
+
+# go-kv/v2/format (i.e. latest)
+BenchmarkFormatV2Append
+BenchmarkFormatV2Append-16 590422 1977 ns/op 488 B/op 23 allocs/op
+BenchmarkFormatV2AppendVerbose
+BenchmarkFormatV2AppendVerbose-16 375628 2981 ns/op 1704 B/op 45 allocs/op
+
+# go-kv/format (i.e. v1)
+BenchmarkFormatAppend
+BenchmarkFormatAppend-16 208357 5883 ns/op 2624 B/op 169 allocs/op
+BenchmarkFormatAppendVerbose
+BenchmarkFormatAppendVerbose-16 35916 33563 ns/op 3734 B/op 208 allocs/op
+
+# fmt (i.e. stdlib)
+BenchmarkFmtAppend
+BenchmarkFmtAppend-16 147722 8418 ns/op 4747 B/op 191 allocs/op
+BenchmarkFmtAppendVerbose
+BenchmarkFmtAppendVerbose-16 167112 7238 ns/op 4401 B/op 178 allocs/op
+
+PASS
+ok codeberg.org/gruf/go-kv/v2/format
+```
diff --git a/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go b/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go
index 8febd4a1d..4c0c1dbda 100644
--- a/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go
+++ b/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go
@@ -84,8 +84,8 @@ func getInterfaceStringerType(t xunsafe.TypeIter) FormatFunc {
// (i.e. non-interface{}) type that has a Stringer{} method receiver.
func getConcreteStringerType(t xunsafe.TypeIter) FormatFunc {
itab := xunsafe.GetIfaceITab[Stringer](t.Type)
- switch t.Indirect() && !t.IfaceIndir() {
- case true:
+ switch {
+ case t.Indirect() && !t.IfaceIndir():
return with_typestr_ptrs(t, func(s *State) {
s.P = *(*unsafe.Pointer)(s.P)
if s.P == nil {
@@ -95,13 +95,23 @@ func getConcreteStringerType(t xunsafe.TypeIter) FormatFunc {
v := *(*Stringer)(xunsafe.PackIface(itab, s.P))
appendString(s, v.String())
})
- case false:
+ case t.Type.Kind() == reflect.Pointer && t.Type.Implements(stringerType):
+ // if the interface implementation is received by
+ // value type, the pointer type will also support
+ // it but it requires an extra dereference check.
return with_typestr_ptrs(t, func(s *State) {
+ if s.P == nil {
+ appendNil(s)
+ return
+ }
v := *(*Stringer)(xunsafe.PackIface(itab, s.P))
appendString(s, v.String())
})
default:
- panic("unreachable")
+ return with_typestr_ptrs(t, func(s *State) {
+ v := *(*Stringer)(xunsafe.PackIface(itab, s.P))
+ appendString(s, v.String())
+ })
}
}
@@ -137,8 +147,8 @@ func getInterfaceFormattableType(t xunsafe.TypeIter) FormatFunc {
// (i.e. non-interface{}) type that has a Formattable{} method receiver.
func getConcreteFormattableType(t xunsafe.TypeIter) FormatFunc {
itab := xunsafe.GetIfaceITab[Formattable](t.Type)
- switch t.Indirect() && !t.IfaceIndir() {
- case true:
+ switch {
+ case t.Indirect() && !t.IfaceIndir():
return with_typestr_ptrs(t, func(s *State) {
s.P = *(*unsafe.Pointer)(s.P)
if s.P == nil {
@@ -148,13 +158,23 @@ func getConcreteFormattableType(t xunsafe.TypeIter) FormatFunc {
v := *(*Formattable)(xunsafe.PackIface(itab, s.P))
v.Format(s)
})
- case false:
+ case t.Type.Kind() == reflect.Pointer && t.Type.Implements(formattableType):
+ // if the interface implementation is received by
+ // value type, the pointer type will also support
+ // it but it requires an extra dereference check.
return with_typestr_ptrs(t, func(s *State) {
+ if s.P == nil {
+ appendNil(s)
+ return
+ }
v := *(*Formattable)(xunsafe.PackIface(itab, s.P))
v.Format(s)
})
default:
- panic("unreachable")
+ return with_typestr_ptrs(t, func(s *State) {
+ v := *(*Formattable)(xunsafe.PackIface(itab, s.P))
+ v.Format(s)
+ })
}
}
@@ -190,8 +210,8 @@ func getInterfaceErrorType(t xunsafe.TypeIter) FormatFunc {
// (i.e. non-interface{}) type that has an error{} method receiver.
func getConcreteErrorType(t xunsafe.TypeIter) FormatFunc {
itab := xunsafe.GetIfaceITab[error](t.Type)
- switch t.Indirect() && !t.IfaceIndir() {
- case true:
+ switch {
+ case t.Indirect() && !t.IfaceIndir():
return with_typestr_ptrs(t, func(s *State) {
s.P = *(*unsafe.Pointer)(s.P)
if s.P == nil {
@@ -201,12 +221,22 @@ func getConcreteErrorType(t xunsafe.TypeIter) FormatFunc {
v := *(*error)(xunsafe.PackIface(itab, s.P))
appendString(s, v.Error())
})
- case false:
+ case t.Type.Kind() == reflect.Pointer && t.Type.Implements(errorType):
+ // if the interface implementation is received by
+ // value type, the pointer type will also support
+ // it but it requires an extra dereference check.
return with_typestr_ptrs(t, func(s *State) {
+ if s.P == nil {
+ appendNil(s)
+ return
+ }
v := *(*error)(xunsafe.PackIface(itab, s.P))
appendString(s, v.Error())
})
default:
- panic("unreachable")
+ return with_typestr_ptrs(t, func(s *State) {
+ v := *(*error)(xunsafe.PackIface(itab, s.P))
+ appendString(s, v.Error())
+ })
}
}