Opened 10 years ago

Closed 10 years ago

Last modified 6 weeks ago

#23968 closed Cleanup/optimization (fixed)

Use generator comprehension instead of list comprehension when possible

Reported by: Jon Dufresne Owned by: nobody
Component: Uncategorized Version: dev
Severity: Normal Keywords:
Cc: jon.dufresne@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Small cleanup to use generator comprehension instead of list comprehension when the called function can easily accept both. This avoids an extra list instance, thus avoid the small overhead of the temporary list.

For example, prefer:

tuple(force_text(item) for item in lst)

over:

tuple([force_text(item) for item in lst])

Patch to follow. Fixes uses of the following functions throughout the codebase.

dict()
tuple()
any()
all()
min()
max()
sorted()
list.extend()
list +=

Change History (6)

comment:1 by Jon Dufresne, 10 years ago

Cc: jon.dufresne@… added
Has patch: set

comment:2 by Collin Anderson, 10 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Collin Anderson, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: newclosed

In 4468c08d70b5b722f3ebd4872909e56580ec7d68:

Fixed #23968 -- Replaced list comprehension with generators and dict comprehension

comment:5 by Tim Graham <timograham@…>, 8 years ago

In 2c69824e:

Refs #23968 -- Removed unnecessary lists, generators, and tuple calls.

comment:6 by Sarah Boyce <42296566+sarahboyce@…>, 6 weeks ago

In 042b381e:

Refs #23968 -- Removed unnecessary list comprehension in contrib.admin.helpers.

Note: See TracTickets for help on using tickets.
Back to Top