Improve the performance of GifWriter._compress()