mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-06 12:03:41 +00:00
reflect: Add FieldByNameFunc
This adds FieldByNameFunc, which some libraries like reflect2 need. For my usecase I could also just stub FieldByNameFunc to panic, but figured that it would work OK to just make it work. I'm not sure if the overhead to FieldByName using a closure is acceptable. Signed-off-by: Tyler Rockwood <rockwood@redpanda.com>
This commit is contained in:
committed by
Ron Evans
parent
dd4e9e86e7
commit
fdc4bbbfad
@@ -1846,6 +1846,17 @@ func (v Value) FieldByName(name string) Value {
|
||||
return Value{}
|
||||
}
|
||||
|
||||
func (v Value) FieldByNameFunc(match func(string) bool) Value {
|
||||
if v.Kind() != Struct {
|
||||
panic(&ValueError{"FieldByName", v.Kind()})
|
||||
}
|
||||
|
||||
if field, ok := v.typecode.FieldByNameFunc(match); ok {
|
||||
return v.FieldByIndex(field.Index)
|
||||
}
|
||||
return Value{}
|
||||
}
|
||||
|
||||
//go:linkname hashmapMake runtime.hashmapMakeUnsafePointer
|
||||
func hashmapMake(keySize, valueSize uintptr, sizeHint uintptr, alg uint8) unsafe.Pointer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user