summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go
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/v2/format/methods.go
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/v2/format/methods.go')
-rw-r--r--vendor/codeberg.org/gruf/go-kv/v2/format/methods.go54
1 files changed, 42 insertions, 12 deletions
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())
+ })
}
}