Call Must(En|De)code instead of (En|De)code to save time

Encode/Decode returns an error code, which we are generally not
checking for sub-objects because we never expect it to fail.  In the
new version of codegen Encode() sets up a panic handler and calls
MustEncode(), and the panic handler has a performance cost.  So just
call MustEncode() and if for some reason the encoding does fail we
will see it as a panic.

We still call Encode/Decode at top level and check the return code.
This commit is contained in:
Bryan Boreham
2017-12-12 17:44:45 +00:00
parent 57b088710d
commit 261e33a3fa
8 changed files with 14 additions and 20 deletions

View File

@@ -133,18 +133,16 @@ func (n NodeSet) fromIntermediate(nodes []Node) NodeSet {
// CodecEncodeSelf implements codec.Selfer
func (n *NodeSet) CodecEncodeSelf(encoder *codec.Encoder) {
if n.psMap != nil {
encoder.Encode(n.toIntermediate())
encoder.MustEncode(n.toIntermediate())
} else {
encoder.Encode(nil)
encoder.MustEncode(nil)
}
}
// CodecDecodeSelf implements codec.Selfer
func (n *NodeSet) CodecDecodeSelf(decoder *codec.Decoder) {
in := []Node{}
if err := decoder.Decode(&in); err != nil {
return
}
decoder.MustDecode(&in)
*n = NodeSet{}.fromIntermediate(in)
}