Optimizing byte generation loop