Decode and encode array directly without for loop

I think this would be a faster way to do it, but I have not benchmarked.