1
1
import abc
2
2
import base64
3
+ import collections
3
4
import contextlib
4
5
from io import BytesIO , TextIOWrapper
5
6
import itertools
@@ -1708,13 +1709,13 @@ def iter_frames(frames=frames):
1708
1709
self ._cache_frame_data = cache_frame_data
1709
1710
1710
1711
# Needs to be initialized so the draw functions work without checking
1711
- self ._save_seq = []
1712
+ self ._save_seq = collections . deque ([], self . _save_count )
1712
1713
1713
1714
super ().__init__ (fig , ** kwargs )
1714
1715
1715
1716
# Need to reset the saved seq, since right now it will contain data
1716
1717
# for a single frame from init, which is not what we want.
1717
- self ._save_seq = []
1718
+ self ._save_seq . clear ()
1718
1719
1719
1720
def new_frame_seq (self ):
1720
1721
# Use the generating function to generate a new frame sequence
@@ -1727,8 +1728,7 @@ def new_saved_frame_seq(self):
1727
1728
if self ._save_seq :
1728
1729
# While iterating we are going to update _save_seq
1729
1730
# so make a copy to safely iterate over
1730
- self ._old_saved_seq = list (self ._save_seq )
1731
- return iter (self ._old_saved_seq )
1731
+ return iter ([* self ._save_seq ])
1732
1732
else :
1733
1733
if self ._save_count is None :
1734
1734
frame_seq = self .new_frame_seq ()
@@ -1773,13 +1773,12 @@ def _init_draw(self):
1773
1773
'return a sequence of Artist objects.' )
1774
1774
for a in self ._drawn_artists :
1775
1775
a .set_animated (self ._blit )
1776
- self ._save_seq = []
1776
+ self ._save_seq . clear ()
1777
1777
1778
1778
def _draw_frame (self , framedata ):
1779
1779
if self ._cache_frame_data :
1780
1780
# Save the data for potential saving of movies.
1781
1781
self ._save_seq .append (framedata )
1782
- self ._save_seq = self ._save_seq [- self ._save_count :]
1783
1782
1784
1783
# Call the func with framedata and args. If blitting is desired,
1785
1784
# func needs to return a sequence of any artists that were modified.
0 commit comments