Improve performance of encodeHeader

Similar to https://github.com/netty/netty/pull/1496  but for 3.6 branch. I am not sure if the next version will be 3.6.x or 3.7. Let me know if you would prefer that I submit for 3.x . Thanks for the quick turnaround on 4!