Avoid un-necessary decode in startsWith/endsWith

As requested in #2503.

Perhaps it's overkill?
Hum... weird.  That shouldn't have compiled. It's an error I meant to write `string optimization = false;` Why didn't the compiler complain? Is the code that badly covered?