Optimizing `replace_once_deep()`.