diff options
author | mathieui <mathieui@mathieui.net> | 2015-05-08 20:37:21 +0200 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2015-05-08 20:37:21 +0200 |
commit | dfd60426d8da06c817c6d3f71901b4f1c013a819 (patch) | |
tree | 79fb8cf31b623cdd846311a0761b34a7b6cfb549 /src/windows/roster_win.py | |
parent | 3171c96eed40d24b3200a8f2af1da9bc7619ab39 (diff) | |
download | poezio-dfd60426d8da06c817c6d3f71901b4f1c013a819.tar.gz poezio-dfd60426d8da06c817c6d3f71901b4f1c013a819.tar.bz2 poezio-dfd60426d8da06c817c6d3f71901b4f1c013a819.tar.xz poezio-dfd60426d8da06c817c6d3f71901b4f1c013a819.zip |
Micro-optimizations on refresh
Reduce the number of calls to config.get whenever possible. Yields a
performance improvement of at least 10% for the basic use case of
"receiving a message in the current tab". Logging stuff isn’t free
either, even when the call should be a no-op, so we should try to make
the debug log less verbose.
Diffstat (limited to 'src/windows/roster_win.py')
-rw-r--r-- | src/windows/roster_win.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/src/windows/roster_win.py b/src/windows/roster_win.py index 6ecb6128..a2e2badd 100644 --- a/src/windows/roster_win.py +++ b/src/windows/roster_win.py @@ -145,6 +145,12 @@ class RosterWin(Win): # draw the roster from the cache roster_view = self.roster_cache[self.start_pos-1:self.start_pos+self.height] + options = { + 'show_roster_sub': config.get('show_roster_subscriptions'), + 'show_s2s_errors': config.get('show_s2s_errors'), + 'show_roster_jids': config.get('show_roster_jids') + } + for item in roster_view: draw_selected = False if y -2 + self.start_pos == self.pos: @@ -155,7 +161,7 @@ class RosterWin(Win): self.draw_group(y, item, draw_selected) group = item.name elif isinstance(item, Contact): - self.draw_contact_line(y, item, draw_selected, group) + self.draw_contact_line(y, item, draw_selected, group, **options) elif isinstance(item, Resource): self.draw_resource_line(y, item, draw_selected) @@ -206,7 +212,8 @@ class RosterWin(Win): return name return name[:self.width - added - 1] + '…' - def draw_contact_line(self, y, contact, colored, group): + def draw_contact_line(self, y, contact, colored, group, show_roster_sub=False, + show_s2s_errors=True, show_roster_jids=False): """ Draw on a line all informations about one contact. This is basically the highest priority resource's informations @@ -229,15 +236,13 @@ class RosterWin(Win): self.addstr(y, 0, ' ') self.addstr(theme.CHAR_STATUS, to_curses_attr(color)) - show_roster_sub = config.get('show_roster_subscriptions') - self.addstr(' ') if resource: self.addstr('[+] ' if contact.folded(group) else '[-] ') added += 4 if contact.ask: added += len(get_theme().CHAR_ROSTER_ASKED) - if config.get('show_s2s_errors') and contact.error: + if show_s2s_errors and contact.error: added += len(get_theme().CHAR_ROSTER_ERROR) if contact.tune: added += len(get_theme().CHAR_ROSTER_TUNE) @@ -250,7 +255,7 @@ class RosterWin(Win): if show_roster_sub in ('all', 'incomplete', 'to', 'from', 'both', 'none'): added += len(theme.char_subscription(contact.subscription, keep=show_roster_sub)) - if not config.get('show_roster_jids') and contact.name: + if not show_roster_jids and contact.name: display_name = '%s' % contact.name elif contact.name and contact.name != contact.bare_jid: display_name = '%s (%s)' % (contact.name, contact.bare_jid) @@ -268,7 +273,7 @@ class RosterWin(Win): self.addstr(theme.char_subscription(contact.subscription, keep=show_roster_sub), to_curses_attr(theme.COLOR_ROSTER_SUBSCRIPTION)) if contact.ask: self.addstr(get_theme().CHAR_ROSTER_ASKED, to_curses_attr(get_theme().COLOR_IMPORTANT_TEXT)) - if config.get('show_s2s_errors') and contact.error: + if show_s2s_errors and contact.error: self.addstr(get_theme().CHAR_ROSTER_ERROR, to_curses_attr(get_theme().COLOR_ROSTER_ERROR)) if contact.tune: self.addstr(get_theme().CHAR_ROSTER_TUNE, to_curses_attr(get_theme().COLOR_ROSTER_TUNE)) |