Optimal regularity in a variational problem for current sheets in ideal magnetohydrodynamics