compiler optimisations for encode and decode

compiler optimisations for encode and decode methods.