Opened 8 years ago

Last modified 8 years ago

#27870 closed Cleanup/optimization

Clean up autocomplete function — at Version 1

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 (1)

comment:1 by Phil, 8 years ago

Description: modified (diff)
Type: UncategorizedCleanup/optimization
Note: See TracTickets for help on using tickets.
Back to Top