Could this be rewritten using `string.each_index` without need for manual iterator? Would it cause noticably worse performance?