@@ -284,13 +284,28 @@ def update_from(self, other):
284
284
self ._linespacing = other ._linespacing
285
285
self .stale = True
286
286
287
+ def _get_layout_cache_key (self , renderer = None ):
288
+ """
289
+ Return a hashable tuple of properties that lets `_get_layout` know
290
+ whether a previously computed layout can be reused.
291
+ """
292
+ x , y = self .get_unitless_position ()
293
+ renderer = renderer or self ._renderer
294
+ return (
295
+ x , y , self .get_text (), hash (self ._fontproperties ),
296
+ self ._verticalalignment , self ._horizontalalignment ,
297
+ self ._linespacing ,
298
+ self ._rotation , self ._rotation_mode , self ._transform_rotates_text ,
299
+ self .figure .dpi , weakref .ref (renderer ),
300
+ )
301
+
287
302
def _get_layout (self , renderer ):
288
303
"""
289
304
Return the extent (bbox) of the text together with
290
305
multiple-alignment information. Note that it returns an extent
291
306
of a rotated text when necessary.
292
307
"""
293
- key = self .get_prop_tup (renderer = renderer )
308
+ key = self ._get_layout_cache_key (renderer = renderer )
294
309
if key in self ._cached :
295
310
return self ._cached [key ]
296
311
@@ -831,6 +846,8 @@ def get_position(self):
831
846
# specified with 'set_x' and 'set_y'.
832
847
return self ._x , self ._y
833
848
849
+ # When removing, also remove the hash(color) check in set_color()
850
+ @_api .deprecated ("3.5" )
834
851
def get_prop_tup (self , renderer = None ):
835
852
"""
836
853
Return a hashable tuple of properties.
@@ -938,7 +955,8 @@ def set_color(self, color):
938
955
# out at draw time for simplicity.
939
956
if not cbook ._str_equal (color , "auto" ):
940
957
mpl .colors ._check_color_like (color = color )
941
- # Make sure it is hashable, or get_prop_tup will fail.
958
+ # Make sure it is hashable, or get_prop_tup will fail (remove this once
959
+ # get_prop_tup is removed).
942
960
try :
943
961
hash (color )
944
962
except TypeError :
0 commit comments