25K seems a little bit excessive to detect indent. Could you consider first counting lines (SAMPLE_LINE_NO) instead? Or reduce the amount of the text parsed?