improve performance of algorithm to convert character map into line number in CLI tool