Merge pull request #7657 from hugovk/optimise-imagecolor

Optimise `ImageColor` using `functools.lru_cache`
This commit is contained in:
Andrew Murray 2023-12-31 19:15:18 +11:00 committed by GitHub
commit 0988703a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,10 +19,12 @@
from __future__ import annotations
import re
from functools import lru_cache
from . import Image
@lru_cache
def getrgb(color):
"""
Convert a color string to an RGB or RGBA tuple. If the string cannot be
@ -121,6 +123,7 @@ def getrgb(color):
raise ValueError(msg)
@lru_cache
def getcolor(color, mode):
"""
Same as :py:func:`~PIL.ImageColor.getrgb` for most modes. However, if