From 056b9ba5a0bea338b2a09b21732e6ee9d354a9c6 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 1 Jun 2025 15:47:00 +0200 Subject: [PATCH] Speed up Terminal.write_yx by avoiding unnecessary blessed.Terminal.length calls. --- ircplom.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ircplom.py b/ircplom.py index e49a684..fc20c1b 100755 --- a/ircplom.py +++ b/ircplom.py @@ -101,7 +101,9 @@ class Terminal: def write_yx(self, offset: YX, msg: str) -> None: 'Starting at offset, write line with msg, padded at end with spaces.' print(self._blessed.move_yx(offset.y, offset.x), end='') - len_with_offset = offset.x + self._blessed.length(msg) + # ._blessed.length can slow down things notably, only use where needed + len_with_offset = offset.x + (len(msg) if msg.isascii() + else self._blessed.length(msg)) if len_with_offset > self.size.x: print(self._blessed.truncate(msg, self.size.x - offset.x), end='') else: @@ -211,7 +213,7 @@ class IrcMessage: self.tags: dict[str, str] = tags or {} def __str__(self) -> str: - return f'[{self.tags}[{self.source}[{self.verb}]]][{self.parameters}]' + return f'[{self.tags}[{self.source}][{self.verb}]]][{self.parameters}]' @classmethod def from_raw(cls, raw_msg: str) -> Self: -- 2.30.2