diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-09-25 21:55:25 +0200 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2018-09-25 21:55:25 +0200 |
commit | 2428084c8d141b5defbfe738f163095ef8bd5be3 (patch) | |
tree | 82d4b1e6d6ebbf6405aeae1011b5a28255a27f56 | |
parent | 6deffb430ef044938f1ed20fa2fdd47022d44970 (diff) | |
download | poezio-2428084c8d141b5defbfe738f163095ef8bd5be3.tar.gz poezio-2428084c8d141b5defbfe738f163095ef8bd5be3.tar.bz2 poezio-2428084c8d141b5defbfe738f163095ef8bd5be3.tar.xz poezio-2428084c8d141b5defbfe738f163095ef8bd5be3.zip |
Cache highlighting regex in a lru.
This makes it way faster than having to create it all the time.
-rw-r--r-- | poezio/tabs/muctab.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/poezio/tabs/muctab.py b/poezio/tabs/muctab.py index 17ab3430..405c2b1f 100644 --- a/poezio/tabs/muctab.py +++ b/poezio/tabs/muctab.py @@ -13,6 +13,7 @@ import logging import os import random import re +import functools from datetime import datetime from typing import Dict, Callable, List, Optional, Union, Set @@ -1251,6 +1252,9 @@ class MucTab(ChatTab): 1, self.width, self.height - 2 - self.core.information_win_size - 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): return re.compile(r"(^|\W)" + re.escape(nickname) + r"(\W|$)", re.I) |