Merge "Fixed performance issue by moving buffer allocation outside loop."