From: Christian Heller Date: Sun, 1 Jun 2025 13:47:00 +0000 (+0200) Subject: Speed up Terminal.write_yx by avoiding unnecessary blessed.Terminal.length calls. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%22https:/validator.w3.org/tasks?a=commitdiff_plain;h=056b9ba5a0bea338b2a09b21732e6ee9d354a9c6;p=ircplom Speed up Terminal.write_yx by avoiding unnecessary blessed.Terminal.length calls. --- 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: