#32901 closed Cleanup/optimization (fixed)
BaseForm.__getitem__() does unneeded work in the happy path
| Reported by: | Chris Jerdonek | Owned by: | Chris Jerdonek |
|---|---|---|---|
| Component: | Forms | 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: | no | UI/UX: | no |
Description
I noticed that in the "happy path," BaseForm.__getitem__() does unneeded work: https://github.com/django/django/blob/fa35c8bdbc6aca65d94d6280fa463d5bc7baa5c0/django/forms/forms.py#L150-L164
It can just return self._bound_fields_cache[name] at the beginning and handle KeyError, instead of accessing self.fields followed by checking for the presence of name in self._bound_fields_cache before doing so each time.
Change History (5)
comment:1 by , 4 years ago
| Triage Stage: | Unreviewed → Accepted |
|---|
comment:2 by , 4 years ago
| Has patch: | set |
|---|
comment:3 by , 4 years ago
| Triage Stage: | Accepted → Ready for checkin |
|---|
Note:
See TracTickets
for help on using tickets.
PR: https://github.com/django/django/pull/14596