Optimize Connection::encode

Looks like there's no meaningful difference, even with the regexp it's still 2 ms. I've made the change anyway.