diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-10-17 18:04:05 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-10-17 18:18:32 +0300 |
commit | 6e1263591b6dcf6451c457f27a64d497d5b26437 (patch) | |
tree | d2457d9f492de1373d28dcc261116fc98a63b1a2 /ttystatus | |
parent | 83e425b995e43fb21585d23d5059b9bd734b7744 (diff) | |
download | python-ttystatus-6e1263591b6dcf6451c457f27a64d497d5b26437.tar.gz |
Use Messager.enabled attribute directly
The method call overhead was quite significant in profiling. Direct
attribute access is much faster. Normally the overhead can be ignored,
but this method gets call quite a lot, so it's worth getting rid of
the overhead.
Diffstat (limited to 'ttystatus')
-rw-r--r-- | ttystatus/messager.py | 20 | ||||
-rw-r--r-- | ttystatus/status.py | 2 | ||||
-rw-r--r-- | ttystatus/status_tests.py | 3 |
3 files changed, 9 insertions, 16 deletions
diff --git a/ttystatus/messager.py b/ttystatus/messager.py index 121ac4d..15f75fb 100644 --- a/ttystatus/messager.py +++ b/ttystatus/messager.py @@ -34,7 +34,7 @@ class Messager(object): def __init__(self, period=None, _terminal=None): self._period = 1.0 if period is None else period - self._enabled = True + self.enabled = True self._cached_message = None # The latest message from caller. self._displayed_message = None # The latest message displayed. @@ -44,25 +44,21 @@ class Messager(object): try: self._terminal.open_tty() except IOError: - self._enabled = False + self.enabled = False if not self._terminal.has_capabilities(): - self._enabled = False + self.enabled = False self._area = ttystatus.AreaManager() self._area.set_terminal(self._terminal) def disable(self): '''Disable all output except notifications.''' - self._enabled = False + self.enabled = False def enable(self): '''Enable output to happen.''' - self._enabled = True - - def is_enabled(self): - '''Is output enabled?''' - return self._enabled + self.enabled = True def time_to_write(self): '''Is it time to write now?''' @@ -87,7 +83,7 @@ class Messager(object): ''' - if self._enabled and self.time_to_write(): + if self.enabled and self.time_to_write(): self.clear() num_lines = len(message.split('\n')) self._area.make_space(num_lines) @@ -119,7 +115,7 @@ class Messager(object): ''' - if self._enabled or force: + if self.enabled or force: self.clear() try: f.write(message) @@ -133,7 +129,7 @@ class Messager(object): def finish(self): '''Finalize output.''' - if self._enabled and self._cached_message is not None: + if self.enabled and self._cached_message is not None: self.write(self._cached_message) if self._cached_message: self._terminal.write('\n') diff --git a/ttystatus/status.py b/ttystatus/status.py index fe90b96..09e0e9f 100644 --- a/ttystatus/status.py +++ b/ttystatus/status.py @@ -100,7 +100,7 @@ class TerminalStatus(object): for w in row: if w.interested_in is None or key in w.interested_in: w.update(self) - if self._m.is_enabled() and self._m.time_to_write(): + if self._m.enabled and self._m.time_to_write(): self._write() def flush(self): diff --git a/ttystatus/status_tests.py b/ttystatus/status_tests.py index 0a96917..ecf91f9 100644 --- a/ttystatus/status_tests.py +++ b/ttystatus/status_tests.py @@ -51,9 +51,6 @@ class DummyMessager(object): def disable(self): self.enabled = False - def is_enabled(self): - return self.enabled - class TerminalStatusTests(unittest.TestCase): |