Opened 8 years ago
Closed 8 years ago
#27870 closed Cleanup/optimization (fixed)
Clean up ManagementUtility.autocomplete()
Reported by: | Phil | Owned by: | Phil |
---|---|---|---|
Component: | Core (Management commands) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
There are few thing in core/management/__init__.py
(https://github.com/django/django/blob/master/django/core/management/__init__.py) those look strange.
- In line 257(https://github.com/django/django/blob/master/django/core/management/__init__.py#L257) there is the code like
sorted(x)[0]
which is similar tomin(x)
. But the second one looks better, works for O(N) but not O(N log N) and doesn't spend memory for the new object.
Sure, time and memory optimizations are negligible in this case, but readability is more important.
- In line 261(https://github.com/django/django/blob/master/django/core/management/__init__.py#L261) we declare list of used options but use only to understand if option was already used. So while we don't need order, but only want to check, if option is already used. So set is better than list both semantically and complexity (~ O(1) instead of O(N)).
Change History (3)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|---|
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 8 years ago
Has patch: | set |
---|---|
Summary: | Clean up autocomplete function → Clean up ManagementUtility.autocomplete() |
Triage Stage: | Unreviewed → Ready for checkin |
Note:
See TracTickets
for help on using tickets.
The PR looks good.