Optimize endsWith