Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

from base64 import b64encode
from collections import namedtuple
import copy
import dataclasses
from functools import lru_cache
from io import BytesIO
Expand Down Expand Up @@ -902,7 +901,12 @@ def set_math_fontfamily(self, fontfamily):

def copy(self):
"""Return a copy of self."""
return copy.copy(self)
# Optimize: direct instance creation instead of using copy.copy(self)
# This avoids unnecessary lookup and internal machinery of copy module for simple objects.
cls = self.__class__
result = cls.__new__(cls)
result.__dict__ = self.__dict__.copy()
return result

# Aliases
set_name = set_family
Expand Down