Opened 3 years ago

Closed 3 years ago

Last modified 18 months ago

#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 Mariusz Felisiak, 3 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:4 by GitHub <noreply@…>, 3 years ago

Resolution: fixed
Status: assignedclosed

In edde2a0:

Fixed #32901 -- Optimized BaseForm.getitem().

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 18 months ago

In 51faf4bd:

Fixed #34148 -- Reverted "Fixed #32901 -- Optimized BaseForm.getitem()."

This reverts commit edde2a069929c93e37835dc3f7c9a229040058e2.

Thanks Jan Pieter Waagmeester for the report.

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