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

Skip to content

Commit c7699a0

Browse files
committed
Implement nested four-level cache
Prevents putting too many files in a single folder
1 parent 00ec4ec commit c7699a0

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/matplotlib/texmanager.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,18 @@ def get_basefile(cls, tex, fontsize, dpi=None):
176176
Return a filename based on a hash of the string, fontsize, and dpi.
177177
"""
178178
src = cls._get_tex_source(tex, fontsize) + str(dpi)
179+
filehash = hashlib.md5(src.encode('utf-8')).hexdigest()
180+
181+
nested_folders = Path()
182+
num_letters, num_levels = 2, 2
183+
for i in range(0, num_letters*num_levels, num_letters):
184+
nested_folders = nested_folders / Path(filehash[i:i+2])
185+
186+
filepath = (Path(cls.texcache) / nested_folders)
187+
filepath.mkdir(parents=True, exist_ok=True)
188+
179189
return os.path.join(
180-
cls.texcache, hashlib.md5(src.encode('utf-8')).hexdigest())
190+
os.path.join(cls.texcache, nested_folders), filehash)
181191

182192
@classmethod
183193
def get_font_preamble(cls):

0 commit comments

Comments
 (0)