Improving performance of lastIndexOf