Opened 4 months ago

Closed 4 months ago

#32990 closed Cleanup/optimization (fixed)

Test the tag_re regex in template/base.py instead of evaluating it every time

Reported by: Chris Jerdonek Owned by: gtwohig
Component: Template system 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

I noticed that template/base.py has a somewhat complicated regex string at the top involving six calls to re.escape() that it needs to evaluate every time: https://github.com/django/django/blob/4fe3774c729f3fd5105b3001fe69a70bdca95ac3/django/template/base.py#L90-L93

A more efficient approach would be to define a hard-coded _TAG_RE_REGEX regex at the top that is the result of that substitution, and add a test checking that it matches the result of calling re.escape() six times, etc. That would eliminate the need to do the substitution at runtime.

Change History (6)

comment:1 Changed 4 months ago by Mariusz Felisiak

Triage Stage: UnreviewedAccepted

comment:2 Changed 4 months ago by gtwohig

Owner: changed from nobody to gtwohig
Status: newassigned

comment:3 Changed 4 months ago by gtwohig

Has patch: set

Submitted PR

comment:4 Changed 4 months ago by Mariusz Felisiak

Triage Stage: AcceptedReady for checkin

comment:5 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In c99aaf14:

Refs #32990 -- Added tests for DebugLexer/Lexer.tokenize().

comment:6 Changed 4 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In fc2bd40f:

Fixed #32990 -- Simplified and optimized tag regex.

Thanks Chris Jerdonek for the review.

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