optimized firstIndexOf()