Commit 2428084c authored by Link Mauve's avatar Link Mauve

Cache highlighting regex in a lru.

This makes it way faster than having to create it all the time.
parent 6deffb43
...@@ -13,6 +13,7 @@ import logging ...@@ -13,6 +13,7 @@ import logging
import os import os
import random import random
import re import re
import functools
from datetime import datetime from datetime import datetime
from typing import Dict, Callable, List, Optional, Union, Set from typing import Dict, Callable, List, Optional, Union, Set
...@@ -1251,6 +1252,9 @@ class MucTab(ChatTab): ...@@ -1251,6 +1252,9 @@ class MucTab(ChatTab):
1, self.width, self.height - 2 - self.core.information_win_size - 1, self.width, self.height - 2 - self.core.information_win_size -
Tab.tab_win_height(), 0) Tab.tab_win_height(), 0)
# This maxsize is kinda arbitrary, but most users won’t have that many
# nicknames anyway.
@functools.lru_cache(maxsize=8)
def build_highlight_regex(self, nickname): def build_highlight_regex(self, nickname):
return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I) return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment