diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-09 03:05:50 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:16:53 -0700 |
commit | 4f05919a0f2695934df2e67399b507896b52c3bc (patch) | |
tree | f9c69c2e1a28b304ec2eb7b40c93ff4d63f14658 /lib/binstruct/structs.go | |
parent | 5bdff4a4fb6c497f3a28c2fc5ba5280233df979e (diff) |
binstruct: Optimize based on the CPU profiler when running scandevices
Diffstat (limited to 'lib/binstruct/structs.go')
-rw-r--r-- | lib/binstruct/structs.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/binstruct/structs.go b/lib/binstruct/structs.go index 52e5406..91bfec7 100644 --- a/lib/binstruct/structs.go +++ b/lib/binstruct/structs.go @@ -69,7 +69,8 @@ type structHandler struct { } type structField struct { - name string + name string + isUnmarshaler bool tag } @@ -82,7 +83,7 @@ func (sh structHandler) Unmarshal(dat []byte, dst reflect.Value) (int, error) { if field.skip { continue } - _n, err := Unmarshal(dat[n:], dst.Field(i).Addr().Interface()) + _n, err := unmarshal(dat[n:], dst.Field(i), field.isUnmarshaler) if err != nil { if _n >= 0 { n += _n @@ -166,8 +167,9 @@ func genStructHandler(structInfo reflect.Type) (structHandler, error) { curOffset += fieldTag.siz ret.fields = append(ret.fields, structField{ - name: fieldInfo.Name, - tag: fieldTag, + name: fieldInfo.Name, + isUnmarshaler: reflect.PtrTo(fieldInfo.Type).Implements(unmarshalerType), + tag: fieldTag, }) } ret.Size = curOffset |