perf: reduce loop count in header parsing