diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2017-01-26 14:21:00 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2017-01-27 10:34:45 -0800 |
commit | 514795d2ec9773b8a66cfdfaede3af0d49ad92b7 (patch) | |
tree | 77c0b1d76f859d8cd7331171c6c4fdd5532d9ba4 /alot/widgets/globals.py | |
parent | bef724a5d142a1ca06476d56015a6c6bcdf89f1b (diff) |
widgets/globals: Optimize sorting TagWidgets
The calculation wants to sort first by length, then by string value (so
'z' would come before 'aa'). The calculation does this by deciding that
if one value has a length of 1, and the other doesn't. Currently it does
this by calling min, and max, and calling len 4 times. This is
pretty inefficient, and more complicated that necessary.
Instead, this patch uses 'is not' with booleans to figure out if one and
only one of the lengths is 1.
Diffstat (limited to 'alot/widgets/globals.py')
-rw-r--r-- | alot/widgets/globals.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py index c4f7379c..60397104 100644 --- a/alot/widgets/globals.py +++ b/alot/widgets/globals.py @@ -326,7 +326,8 @@ class TagWidget(urwid.AttrMap): self_len = len(self.translated) oth_len = len(other.translated) - if min(self_len, oth_len) == 1 and max(self_len, oth_len) > 1: + + if (self_len == 1) is not (oth_len == 1): return self_len < oth_len return self.translated.lower() < other.translated.lower() |