diff options
author | Lars Wirzenius <liw@liw.fi> | 2012-04-08 08:31:19 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2012-04-08 08:31:19 +0100 |
commit | 9b4eb176da39e43d357abdc4ffecb17b3d291f48 (patch) | |
tree | fd9b50b7a98bea55668024a93040efcd7e69ab49 | |
parent | 08c395e7105f2cedf0e13dde566a6cddd68de92b (diff) | |
download | python-ttystatus-9b4eb176da39e43d357abdc4ffecb17b3d291f48.tar.gz |
Only format widgets when it's time to write
This saves a lot of CPU time when there's a lot of updates
during an update period. Obnam, for example, does that,
and ttystatus was visible in its benchmarks.
-rw-r--r-- | ttystatus/status.py | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/ttystatus/status.py b/ttystatus/status.py index 24f369b..54c6049 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -77,16 +77,17 @@ class TerminalStatus(object): def __setitem__(self, key, value): '''Set value for key.''' self._values[key] = value - width = self._m.width - if width != self._latest_width: - widgets = self._widgets - self._latest_width = width - else: - widgets = self._interests.get(key, []) + self._wildcards - for w in widgets: - w.update(self, width) - width -= len(str(w)) - self._m.write(''.join(str(w) for w in self._widgets)) + if self._m.time_to_write(): + width = self._m.width + if width != self._latest_width: + widgets = self._widgets + self._latest_width = width + else: + widgets = self._interests.get(key, []) + self._wildcards + for w in widgets: + w.update(self, width) + width -= len(str(w)) + self._m.write(''.join(str(w) for w in self._widgets)) def increase(self, key, delta): '''Increase value for a key by a given amount.''' |