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

Skip to content

Commit 8cb06a8

Browse files
committed
Globally cache single TexManager and TextToPath instances.
This allows sharing their caches across renderer instances. (If it was up to me these classes would be replaced by module-level functions and a module-level cache, but heh.)
1 parent 0c35833 commit 8cb06a8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/texmanager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"""
3030

3131
import copy
32+
import functools
3233
import glob
3334
import hashlib
3435
import logging
@@ -48,6 +49,8 @@
4849
class TexManager(object):
4950
"""
5051
Convert strings to dvi files using TeX, caching the results to a directory.
52+
53+
Repeated calls to this constructor always return the same instance.
5154
"""
5255

5356
cachedir = mpl.get_cachedir()
@@ -95,6 +98,10 @@ class TexManager(object):
9598
('text.latex.preamble', 'text.latex.unicode', 'text.latex.preview',
9699
'font.family') + tuple('font.' + n for n in font_families))
97100

101+
@functools.lru_cache() # Always return the same instance.
102+
def __new__(cls):
103+
return object.__new__(cls)
104+
98105
def __init__(self):
99106

100107
if self.texcache is None:

lib/matplotlib/textpath.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,18 @@ def _get_adobe_standard_encoding():
2525

2626
class TextToPath(object):
2727
"""
28-
A class that convert a given text to a path using ttf fonts.
28+
A class that converts strings to paths.
29+
30+
Repeated calls to this constructor always return the same instance.
2931
"""
3032

3133
FONT_SCALE = 100.
3234
DPI = 72
3335

36+
@functools.lru_cache() # Always return the same instance.
37+
def __new__(cls):
38+
return object.__new__(cls)
39+
3440
def __init__(self):
3541
self.mathtext_parser = MathTextParser('path')
3642
self._texmanager = None

0 commit comments

Comments
 (0)