Optimized indexOf calculation