Escaping performance improvement

Hi Johan,
here is a wee patch to improve the performance of the escape function. In my benchmarks, the new version is between 10% (if the string doesn't need to be escaped) and 50% (if it does) faster than the old version. Your benchmarks show a ~15% improvement in encoding performance.
The tests still pass.
Cheers,
Florian