Opened 10 months ago

Closed 10 months ago

Last modified 10 months ago

#32601 closed Cleanup/optimization (duplicate)

Optimize split_domain_port() by leveraging the regex

Reported by: Chris Jerdonek Owned by: nobody
Component: HTTP handling Version: dev
Severity: Normal Keywords: split_domain_port, regex
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I noticed that almost all of the pure Python can be removed from Django's split_domain_port() function:
https://github.com/django/django/blob/2f13c476abe4ba787b6cb71131818341911f43cc/django/http/request.py#L643-L650
by modifying the host_validation_re regex slightly and then accessing it via its groups:
https://github.com/django/django/blob/2f13c476abe4ba787b6cb71131818341911f43cc/django/http/request.py#L26
Currently, the function uses the regex to determine if there's a match, and then uses pure Python to reparse out the components (work which the regex has already done for the most part).

I can do this once accepted.

Change History (3)

comment:1 Changed 10 months ago by Mariusz Felisiak

Resolution: duplicate
Status: newclosed

Thanks for the suggestion, this optimization has already been proposed as a part of #31354, see PR. I think we can keep it there and merge it before the main fix.

comment:2 Changed 10 months ago by Chris Jerdonek

Thanks for the pointer. That PR doesn't contain all the optimizations I had in mind, though. There is more pure Python that can be removed.

comment:3 Changed 10 months ago by Chris Jerdonek

I was also going to add more tests as part of my change because currently there is only one test case (testing dot removal): https://github.com/django/django/blob/2f13c476abe4ba787b6cb71131818341911f43cc/tests/requests/tests.py#L813-L816

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