reduce regex calls in name highlighting

This commit is contained in:
nebula 2025-05-05 00:26:53 +00:00
parent d17d9ccf09
commit 070ed21dde

View File

@ -142,10 +142,12 @@ class App():
post_user = post["user"] post_user = post["user"]
time_seconds = post["time"] / 1_000_000_000 time_seconds = post["time"] / 1_000_000_000
stamp = datetime.datetime.fromtimestamp(time_seconds) stamp = datetime.datetime.fromtimestamp(time_seconds)
if current_user != post_user and name_re.search(body): if current_user != post_user:
search = name_re.finditer(body)
if search:
widget_body = [] widget_body = []
index = 0 index = 0
for match in name_re.finditer(body): for match in search:
start, end = match.span() start, end = match.span()
before = body[index:start] before = body[index:start]
highlight = body[start:end] highlight = body[start:end]