diff options
| author | 2025-08-10 15:05:54 +0200 | |
|---|---|---|
| committer | 2025-08-10 15:05:54 +0200 | |
| commit | 67100809b399b60e58490fa8b1c0a72be75ac820 (patch) | |
| tree | ae6df939bf9fe557a766120bee3363f89b47f961 /vendor/codeberg.org/gruf/go-kv/v2/format/methods.go | |
| parent | [feature + performance] add JSON logging format (#4355) (diff) | |
| download | gotosocial-67100809b399b60e58490fa8b1c0a72be75ac820.tar.xz | |
[chore] update dependencies (#4361)
- codeberg.org/gruf/go-kv/v2 v2.0.5 => v2.0.6
- github.com/coreos/go-oidc/v3 v3.14.1 => v3.15.0
- github.com/miekg/dns v1.1.67 => v1.1.68
- github.com/tdewolff/minify/v2 v2.23.9 => v2.23.11
- github.com/yuin/goldmark v1.7.12 => v1.7.13
- golang.org/x/crypto v0.40.0 => v0.41.0
- golang.org/x/image v0.29.0 => v0.30.0
- golang.org/x/net v0.42.0 => v0.43.0
- golang.org/x/sys v0.34.0 => v0.35.0
- golang.org/x/text v0.27.0 => v0.28.0
- modernc.org/sqlite v1.38.0 => v1.38.2
Reviewed-on: https://codeberg.org/superseriousbusiness/gotosocial/pulls/4361
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.go | 115 |
1 files changed, 87 insertions, 28 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 fcbffd3a4..8febd4a1d 100644 --- a/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go +++ b/vendor/codeberg.org/gruf/go-kv/v2/format/methods.go @@ -3,31 +3,45 @@ package format import ( "reflect" "unsafe" + + "codeberg.org/gruf/go-xunsafe" ) type Stringer interface{ String() string } +type Formattable interface{ Format(*State) } + var ( // stringer type for implement checks. stringerType = typeof[Stringer]() + // formattableType type for implement checks. + formattableType = typeof[Formattable]() + // error type for implement checks. errorType = typeof[error]() ) // getMethodType returns a *possible* FormatFunc to handle case // of a type that implements any known interface{} types, else nil. -func getMethodType(t typenode) FormatFunc { +func getMethodType(t xunsafe.TypeIter) FormatFunc { switch { - case t.rtype.Implements(stringerType): - switch t.rtype.Kind() { + case t.Type.Implements(stringerType): + switch t.Type.Kind() { case reflect.Interface: return getInterfaceStringerType(t) default: return getConcreteStringerType(t) } - case t.rtype.Implements(errorType): - switch t.rtype.Kind() { + case t.Type.Implements(formattableType): + switch t.Type.Kind() { + case reflect.Interface: + return getInterfaceFormattableType(t) + default: + return getConcreteFormattableType(t) + } + case t.Type.Implements(errorType): + switch t.Type.Kind() { case reflect.Interface: return getInterfaceErrorType(t) default: @@ -40,12 +54,12 @@ func getMethodType(t typenode) FormatFunc { // getInterfaceStringerType returns a FormatFunc to handle case of an interface{} // type that implements Stringer{}, i.e. Stringer{} itself and any superset of. -func getInterfaceStringerType(t typenode) FormatFunc { - switch t.indirect() && !t.iface_indir() { +func getInterfaceStringerType(t xunsafe.TypeIter) FormatFunc { + switch t.Indirect() && !t.IfaceIndir() { case true: return with_typestr_ptrs(t, func(s *State) { s.P = *(*unsafe.Pointer)(s.P) - if s.P == nil || (*abi_NonEmptyInterface)(s.P).Data == nil { + if s.P == nil || (*xunsafe.Abi_NonEmptyInterface)(s.P).Data == nil { appendNil(s) return } @@ -54,7 +68,7 @@ func getInterfaceStringerType(t typenode) FormatFunc { }) case false: return with_typestr_ptrs(t, func(s *State) { - if s.P == nil || (*abi_NonEmptyInterface)(s.P).Data == nil { + if s.P == nil || (*xunsafe.Abi_NonEmptyInterface)(s.P).Data == nil { appendNil(s) return } @@ -68,9 +82,9 @@ func getInterfaceStringerType(t typenode) FormatFunc { // getConcreteStringerType returns a FormatFunc to handle case of concrete // (i.e. non-interface{}) type that has a Stringer{} method receiver. -func getConcreteStringerType(t typenode) FormatFunc { - itab := get_iface_ITab[Stringer](t.rtype) - switch t.indirect() && !t.iface_indir() { +func getConcreteStringerType(t xunsafe.TypeIter) FormatFunc { + itab := xunsafe.GetIfaceITab[Stringer](t.Type) + switch t.Indirect() && !t.IfaceIndir() { case true: return with_typestr_ptrs(t, func(s *State) { s.P = *(*unsafe.Pointer)(s.P) @@ -78,17 +92,66 @@ func getConcreteStringerType(t typenode) FormatFunc { appendNil(s) return } - v := *(*Stringer)(pack_iface(itab, s.P)) + v := *(*Stringer)(xunsafe.PackIface(itab, s.P)) appendString(s, v.String()) }) case false: return with_typestr_ptrs(t, func(s *State) { + v := *(*Stringer)(xunsafe.PackIface(itab, s.P)) + appendString(s, v.String()) + }) + default: + panic("unreachable") + } +} + +// getInterfaceFormattableType returns a FormatFunc to handle case of an interface{} +// type that implements Formattable{}, i.e. Formattable{} itself and any superset of. +func getInterfaceFormattableType(t xunsafe.TypeIter) FormatFunc { + switch t.Indirect() && !t.IfaceIndir() { + case true: + return with_typestr_ptrs(t, func(s *State) { + s.P = *(*unsafe.Pointer)(s.P) + if s.P == nil || (*xunsafe.Abi_NonEmptyInterface)(s.P).Data == nil { + appendNil(s) + return + } + v := *(*Formattable)(s.P) + v.Format(s) + }) + case false: + return with_typestr_ptrs(t, func(s *State) { + if s.P == nil || (*xunsafe.Abi_NonEmptyInterface)(s.P).Data == nil { + appendNil(s) + return + } + v := *(*Formattable)(s.P) + v.Format(s) + }) + default: + panic("unreachable") + } +} + +// getConcreteFormattableType returns a FormatFunc to handle case of concrete +// (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: + return with_typestr_ptrs(t, func(s *State) { + s.P = *(*unsafe.Pointer)(s.P) if s.P == nil { appendNil(s) return } - v := *(*Stringer)(pack_iface(itab, s.P)) - appendString(s, v.String()) + v := *(*Formattable)(xunsafe.PackIface(itab, s.P)) + v.Format(s) + }) + case false: + return with_typestr_ptrs(t, func(s *State) { + v := *(*Formattable)(xunsafe.PackIface(itab, s.P)) + v.Format(s) }) default: panic("unreachable") @@ -97,12 +160,12 @@ func getConcreteStringerType(t typenode) FormatFunc { // getInterfaceErrorType returns a FormatFunc to handle case of an interface{} // type that implements error{}, i.e. error{} itself and any superset of. -func getInterfaceErrorType(t typenode) FormatFunc { - switch t.indirect() && !t.iface_indir() { +func getInterfaceErrorType(t xunsafe.TypeIter) FormatFunc { + switch t.Indirect() && !t.IfaceIndir() { case true: return with_typestr_ptrs(t, func(s *State) { s.P = *(*unsafe.Pointer)(s.P) - if s.P == nil || (*abi_NonEmptyInterface)(s.P).Data == nil { + if s.P == nil || (*xunsafe.Abi_NonEmptyInterface)(s.P).Data == nil { appendNil(s) return } @@ -111,7 +174,7 @@ func getInterfaceErrorType(t typenode) FormatFunc { }) case false: return with_typestr_ptrs(t, func(s *State) { - if s.P == nil || (*abi_NonEmptyInterface)(s.P).Data == nil { + if s.P == nil || (*xunsafe.Abi_NonEmptyInterface)(s.P).Data == nil { appendNil(s) return } @@ -125,9 +188,9 @@ func getInterfaceErrorType(t typenode) FormatFunc { // getConcreteErrorType returns a FormatFunc to handle case of concrete // (i.e. non-interface{}) type that has an error{} method receiver. -func getConcreteErrorType(t typenode) FormatFunc { - itab := get_iface_ITab[error](t.rtype) - switch t.indirect() && !t.iface_indir() { +func getConcreteErrorType(t xunsafe.TypeIter) FormatFunc { + itab := xunsafe.GetIfaceITab[error](t.Type) + switch t.Indirect() && !t.IfaceIndir() { case true: return with_typestr_ptrs(t, func(s *State) { s.P = *(*unsafe.Pointer)(s.P) @@ -135,16 +198,12 @@ func getConcreteErrorType(t typenode) FormatFunc { appendNil(s) return } - v := *(*error)(pack_iface(itab, s.P)) + v := *(*error)(xunsafe.PackIface(itab, s.P)) appendString(s, v.Error()) }) case false: return with_typestr_ptrs(t, func(s *State) { - if s.P == nil { - appendNil(s) - return - } - v := *(*error)(pack_iface(itab, s.P)) + v := *(*error)(xunsafe.PackIface(itab, s.P)) appendString(s, v.Error()) }) default: |
