From 9158c9aec029bb4aaa2fca7040f04ff030536a0f Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Tue, 26 Dec 2023 19:03:18 +0200 Subject: [PATCH] Optimise ImageColor using functools.lru_cache --- src/PIL/ImageColor.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PIL/ImageColor.py b/src/PIL/ImageColor.py index bfad27c82d6..ad59b066779 100644 --- a/src/PIL/ImageColor.py +++ b/src/PIL/ImageColor.py @@ -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