summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org/gruf/go-structr/runtime.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2024-05-13 08:05:46 +0000
committerLibravatar GitHub <noreply@github.com>2024-05-13 08:05:46 +0000
commitc06e6fb6561595adc80ce5191640ae442771d45c (patch)
tree58845f63151eff4e984351575eea67f5e82a6c82 /vendor/codeberg.org/gruf/go-structr/runtime.go
parent[bugfix] Reset emoji fields on upload error (#2905) (diff)
downloadgotosocial-c06e6fb6561595adc80ce5191640ae442771d45c.tar.xz
[performance] update go-structr and go-mutexes with memory usage improvements (#2909)
* update go-structr and go-mutexes with memory usage improvements * bump to go-structr v0.8.4
Diffstat (limited to 'vendor/codeberg.org/gruf/go-structr/runtime.go')
-rw-r--r--vendor/codeberg.org/gruf/go-structr/runtime.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/vendor/codeberg.org/gruf/go-structr/runtime.go b/vendor/codeberg.org/gruf/go-structr/runtime.go
index 9990fe7b9..a4696187a 100644
--- a/vendor/codeberg.org/gruf/go-structr/runtime.go
+++ b/vendor/codeberg.org/gruf/go-structr/runtime.go
@@ -29,10 +29,15 @@ type struct_field struct {
// (i.e. fast serializing) fn.
mangle mangler.Mangler
+ // zero value data, used when
+ // nil encountered during ptr
+ // offset following.
+ zero unsafe.Pointer
+
// mangled zero value string,
// if set this indicates zero
// values of field not allowed
- zero string
+ zerostr string
}
// next_offset defines a next offset location
@@ -106,13 +111,14 @@ func find_field(t reflect.Type, names []string) (sfield struct_field) {
// Get field type as reflect2.
sfield.type2 = reflect2.Type2(t)
- i := sfield.type2.New()
// Find mangler for field type.
sfield.mangle = mangler.Get(t)
- // Set possible mangled zero value.
- sfield.zero = string(sfield.mangle(nil, i))
+ // Set possible zero value and its string.
+ sfield.zero = sfield.type2.UnsafeNew()
+ i := sfield.type2.UnsafeIndirect(sfield.zero)
+ sfield.zerostr = string(sfield.mangle(nil, i))
return
}
@@ -130,8 +136,11 @@ func extract_fields(ptr unsafe.Pointer, fields []struct_field) []any {
for _, offset := range field.offsets {
// Dereference any ptrs to offset.
fptr = deref(fptr, offset.derefs)
+
if fptr == nil {
- return nil
+ // Use zero value.
+ fptr = field.zero
+ break
}
// Jump forward by offset to next ptr.