From 47aecf700da3c36c69d30c08f3cf8284a769d93f Mon Sep 17 00:00:00 2001 From: freiheit Date: Thu, 21 Mar 2024 00:08:33 -0700 Subject: [PATCH] Add caching to `parse_dice`, to slightly speed things up when called with same dice string repeatedly --- mvkroller.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mvkroller.py b/mvkroller.py index 5dbb31d..e383d49 100644 --- a/mvkroller.py +++ b/mvkroller.py @@ -19,6 +19,7 @@ # https://github.com/freiheit/MvKDiceBot """MvKRoller: Dice roller for the MvKDiceBot""" +import functools import logging import random import re @@ -40,6 +41,7 @@ def getMessage(self): return self.message +@functools.cache def parse_dice(dicestr: str): """Parses the dice string and returns a dictionary of dieSize->count""" # types of dice we're looking for: