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