python: Simplify list sorting
authorMathieu Bridon <bochecha@daitauha.fr>
Thu, 9 Aug 2018 08:27:24 +0000 (10:27 +0200)
committerDylan Baker <dylan@pnwbakers.com>
Thu, 9 Aug 2018 23:49:19 +0000 (16:49 -0700)
Instead of copying the list, then sorting the copy in-place, we can just
get a new sorted copy directly.

Signed-off-by: Mathieu Bridon <bochecha@daitauha.fr>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
Reviewed-by: Dylan Baker <dylan@pnwbakers.com>
src/mapi/mapi_abi.py

index d4c48ec430086d49e0422d6352bf95ded9b37648..dc48fa5935fdcd55197184c43f30cb62c9a5e871 100644 (file)
@@ -291,8 +291,7 @@ class ABIPrinter(object):
         self.entries = entries
 
         # sort entries by their names
-        self.entries_sorted_by_names = self.entries[:]
-        self.entries_sorted_by_names.sort(key=attrgetter('name'))
+        self.entries_sorted_by_names = sorted(self.entries, key=attrgetter('name'))
 
         self.indent = ' ' * 3
         self.noop_warn = 'noop_warn'
@@ -441,8 +440,7 @@ class ABIPrinter(object):
     def c_stub_string_pool(self):
         """Return the string pool for use by stubs."""
         # sort entries by their names
-        sorted_entries = self.entries[:]
-        sorted_entries.sort(key=attrgetter('name'))
+        sorted_entries = sorted(self.entries, key=attrgetter('name'))
 
         pool = []
         offsets = {}