mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Use faster marshalling method for non primitive struct fields.
In autogenerating the implementation of Marshallable.MarshalBytes(), we were using the slower MarshalBytes(). Instead use MarshalUnsafe which is faster and falls back to slow MarshalBytes() if the type is not packed. Even if the outer struct is not packed, we can at least do fast marshalling on its packed fields. PiperOrigin-RevId: 408268469
This commit is contained in:
@@ -132,7 +132,7 @@ func (g *interfaceGenerator) marshalScalar(accessor, typ, bufVar string) {
|
||||
g.emit("hostarch.ByteOrder.PutUint64(%s[:8], uint64(%s))\n", bufVar, accessor)
|
||||
g.shift(bufVar, 8)
|
||||
default:
|
||||
g.emit("%s = %s.MarshalBytes(%s)\n", bufVar, accessor, bufVar)
|
||||
g.emit("%s = %s.MarshalUnsafe(%s)\n", bufVar, accessor, bufVar)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func (g *interfaceGenerator) unmarshalScalar(accessor, typ, bufVar string) {
|
||||
g.emit("%s = %s(hostarch.ByteOrder.Uint64(%s[:8]))\n", accessor, typ, bufVar)
|
||||
g.shift(bufVar, 8)
|
||||
default:
|
||||
g.emit("%s = %s.UnmarshalBytes(%s)\n", bufVar, accessor, bufVar)
|
||||
g.emit("%s = %s.UnmarshalUnsafe(%s)\n", bufVar, accessor, bufVar)
|
||||
g.recordPotentiallyNonPackedField(accessor)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user