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 Phil)

There are few thing in core/management/__init__.py(https://github.com/django/django/blob/master/django/core/management/__init__.py) those look strange.

  1. 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 to min(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.

  1. 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 Phil, 8 years ago

Description: modified (diff)
Type: UncategorizedCleanup/optimization

comment:2 by Tim Graham, 8 years ago

Has patch: set
Summary: Clean up autocomplete functionClean up ManagementUtility.autocomplete()
Triage Stage: UnreviewedReady for checkin

The PR looks good.

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

Resolution: fixed
Status: assignedclosed

In cc5c1b75:

Fixed #27870 -- Cleaned up ManagementUtility.autocomplete().

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