perf(commands/utils): use lru cache for matching
This commit is contained in:
parent
672ae02e16
commit
32c7be659b
@ -1,4 +1,5 @@
|
|||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from functools import lru_cache
|
||||||
|
|
||||||
import constants
|
import constants
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ class Command(Enum):
|
|||||||
VOLUME = "volume"
|
VOLUME = "volume"
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
def match_token(token: str) -> list[Command]:
|
def match_token(token: str) -> list[Command]:
|
||||||
if token.lower() == "r":
|
if token.lower() == "r":
|
||||||
return [Command.RELOAD]
|
return [Command.RELOAD]
|
||||||
@ -44,11 +46,13 @@ def match_token(token: str) -> list[Command]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
def match(command: str) -> list[Command] | None:
|
def match(command: str) -> list[Command] | None:
|
||||||
if tokens := tokenize(command):
|
if tokens := tokenize(command):
|
||||||
return match_token(tokens[0])
|
return match_token(tokens[0])
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
def tokenize(string: str) -> list[str]:
|
def tokenize(string: str) -> list[str]:
|
||||||
tokens = []
|
tokens = []
|
||||||
token = ""
|
token = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user