|
|
@@ -55,6 +55,9 @@ func toField(f *reflect.StructField) field {
|
|
|
// invalidField is an invalid field identifier.
|
|
|
const invalidField = ^field(0)
|
|
|
|
|
|
+// zeroField is a noop when calling pointer.offset.
|
|
|
+const zeroField = field(0)
|
|
|
+
|
|
|
// IsValid reports whether the field identifier is valid.
|
|
|
func (f field) IsValid() bool {
|
|
|
return f != invalidField
|
|
|
@@ -102,6 +105,13 @@ func valToPointer(v reflect.Value) pointer {
|
|
|
// offset converts from a pointer to a structure to a pointer to
|
|
|
// one of its fields.
|
|
|
func (p pointer) offset(f field) pointer {
|
|
|
+ // For safety, we should panic if !f.IsValid, however calling panic causes
|
|
|
+ // this to no longer be inlineable, which is a serious performance cost.
|
|
|
+ /*
|
|
|
+ if !f.IsValid() {
|
|
|
+ panic("invalid field")
|
|
|
+ }
|
|
|
+ */
|
|
|
return pointer{p: unsafe.Pointer(uintptr(p.p) + uintptr(f))}
|
|
|
}
|
|
|
|