micro-optimization: sorted() can take any iterable and returns a list

So there is no need to convert everything to lists before and after.
Also, all_formats is immediately converted to a set, and kept that way,
so it does not need to always be accessed as set(all_formats).
This commit is contained in:
Eli Schwartz 2019-08-28 11:53:07 -04:00
parent 04a37cdf3b
commit c9f8ffedb1
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6

View File

@ -35,11 +35,11 @@ class ConfigWidget(QWidget, Ui_ConfigWidget):
except TypeError: except TypeError:
self.device_name = getattr(device, 'gui_name', None) or _('Device') self.device_name = getattr(device, 'gui_name', None) or _('Device')
if device.USER_CAN_ADD_NEW_FORMATS: if device.USER_CAN_ADD_NEW_FORMATS:
all_formats = set(all_formats) | set(BOOK_EXTENSIONS) all_formats = all_formats | set(BOOK_EXTENSIONS)
format_map = settings.format_map format_map = settings.format_map
disabled_formats = list(set(all_formats).difference(format_map)) disabled_formats = all_formats.difference(format_map)
for format in format_map + list(sorted(disabled_formats)): for format in format_map + sorted(disabled_formats):
item = QListWidgetItem(format, self.columns) item = QListWidgetItem(format, self.columns)
item.setData(Qt.UserRole, (format)) item.setData(Qt.UserRole, (format))
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable) item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)