Efficient computation of Green's functions for one-dimensional periodic structures in layered media