Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a7d146e

Browse files
committed
More cleanups, mostly centered around caching.
1 parent 68d24f6 commit a7d146e

File tree

7 files changed

+25
-38
lines changed

7 files changed

+25
-38
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Removed attributes
2+
``````````````````
3+
The unused `FONT_SCALE` and `fontd` attributes of the `RendererSVG` class have
4+
been removed.

lib/matplotlib/backends/backend_agg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from matplotlib import verbose, rcParams, __version__
3232
from matplotlib.backend_bases import (
3333
_Backend, FigureCanvasBase, FigureManagerBase, RendererBase, cursors)
34-
from matplotlib.cbook import maxdict
3534
from matplotlib.figure import Figure
3635
from matplotlib.font_manager import findfont, get_font
3736
from matplotlib.ft2font import (LOAD_FORCE_AUTOHINT, LOAD_NO_HINTING,

lib/matplotlib/backends/backend_svg.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
_Backend, FigureCanvasBase, FigureManagerBase, GraphicsContextBase,
2020
RendererBase)
2121
from matplotlib.backends.backend_mixed import MixedModeRenderer
22-
from matplotlib.cbook import is_writable_file_like, maxdict
22+
from matplotlib.cbook import is_writable_file_like
2323
from matplotlib.colors import rgb2hex
2424
from matplotlib.figure import Figure
2525
from matplotlib.font_manager import findfont, FontProperties, get_font
@@ -258,9 +258,6 @@ def generate_css(attrib={}):
258258

259259
_capstyle_d = {'projecting' : 'square', 'butt' : 'butt', 'round': 'round',}
260260
class RendererSVG(RendererBase):
261-
FONT_SCALE = 100.0
262-
fontd = maxdict(50)
263-
264261
def __init__(self, width, height, svgwriter, basename=None, image_dpi=72):
265262
self.width = width
266263
self.height = height

lib/matplotlib/colors.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ def _is_nth_color(c):
101101

102102
def is_color_like(c):
103103
"""Return whether *c* can be interpreted as an RGB(A) color."""
104-
# Special-case nth color syntax because it cannot be parsed during
105-
# setup.
104+
# Special-case nth color syntax because it cannot be parsed during setup.
106105
if _is_nth_color(c):
107106
return True
108107
try:

lib/matplotlib/mathtext.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
import unicodedata
2626
from warnings import warn
2727

28+
try:
29+
from functools import lru_cache
30+
except ImportError: # Py2
31+
from backports.functools_lru_cache import lru_cache
32+
2833
from numpy import inf, isinf
2934
import numpy as np
3035

@@ -3257,8 +3262,8 @@ def __init__(self, output):
32573262
Create a MathTextParser for the given backend *output*.
32583263
"""
32593264
self._output = output.lower()
3260-
self._cache = maxdict(50)
32613265

3266+
@lru_cache(50)
32623267
def parse(self, s, dpi = 72, prop = None):
32633268
"""
32643269
Parse the given math expression *s* at the given *dpi*. If
@@ -3270,16 +3275,10 @@ def parse(self, s, dpi = 72, prop = None):
32703275
The results are cached, so multiple calls to :meth:`parse`
32713276
with the same expression should be fast.
32723277
"""
3273-
# There is a bug in Python 3.x where it leaks frame references,
3274-
# and therefore can't handle this caching
3278+
32753279
if prop is None:
32763280
prop = FontProperties()
32773281

3278-
cacheKey = (s, dpi, hash(prop))
3279-
result = self._cache.get(cacheKey)
3280-
if result is not None:
3281-
return result
3282-
32833282
if self._output == 'ps' and rcParams['ps.useafm']:
32843283
font_output = StandardPsFonts(prop)
32853284
else:
@@ -3302,9 +3301,7 @@ def parse(self, s, dpi = 72, prop = None):
33023301

33033302
box = self._parser.parse(s, font_output, fontsize, dpi)
33043303
font_output.set_canvas_size(box.width, box.height, box.depth)
3305-
result = font_output.get_results(box)
3306-
self._cache[cacheKey] = result
3307-
return result
3304+
return font_output.get_results(box)
33083305

33093306
def to_mask(self, texstr, dpi=120, fontsize=14):
33103307
"""

lib/matplotlib/path.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
import math
2121
from weakref import WeakValueDictionary
2222

23+
try:
24+
from functools import lru_cache
25+
except ImportError: # Py2
26+
from backports.functools_lru_cache import lru_cache
27+
2328
import numpy as np
2429

2530
from . import _path, rcParams
@@ -942,27 +947,17 @@ def wedge(cls, theta1, theta2, n=None):
942947
"""
943948
return cls.arc(theta1, theta2, n, True)
944949

945-
_hatch_dict = maxdict(8)
946-
947-
@classmethod
948-
def hatch(cls, hatchpattern, density=6):
950+
@staticmethod
951+
@lru_cache(8)
952+
def hatch(hatchpattern, density=6):
949953
"""
950954
Given a hatch specifier, *hatchpattern*, generates a Path that
951955
can be used in a repeated hatching pattern. *density* is the
952956
number of lines per unit square.
953957
"""
954958
from matplotlib.hatch import get_path
955-
956-
if hatchpattern is None:
957-
return None
958-
959-
hatch_path = cls._hatch_dict.get((hatchpattern, density))
960-
if hatch_path is not None:
961-
return hatch_path
962-
963-
hatch_path = get_path(hatchpattern, density)
964-
cls._hatch_dict[(hatchpattern, density)] = hatch_path
965-
return hatch_path
959+
return (get_path(hatchpattern, density)
960+
if hatchpattern is not None else None)
966961

967962
def clip_to_bbox(self, bbox, inside=True):
968963
"""

lib/matplotlib/textpath.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class TextToPath(object):
3333
DPI = 72
3434

3535
def __init__(self):
36-
"""
37-
Initialization
38-
"""
3936
self.mathtext_parser = MathTextParser('path')
4037
self.tex_font_map = None
4138

@@ -492,8 +489,7 @@ def _revalidate_path(self):
492489
necessary.
493490
494491
"""
495-
if (self._invalid or
496-
(self._cached_vertices is None)):
492+
if self._invalid or self._cached_vertices is None:
497493
tr = Affine2D().scale(
498494
self._size / text_to_path.FONT_SCALE,
499495
self._size / text_to_path.FONT_SCALE).translate(*self._xy)

0 commit comments

Comments
 (0)