Improve performance of encodeHeader. Avoid array creation.