Opened 3 years ago

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

Triage Stage: UnreviewedAccepted

comment:2 by gtwohig, 3 years ago

Owner: changed from nobody to gtwohig
Status: newassigned

comment:3 by gtwohig, 3 years ago

Has patch: set

Submitted PR

comment:4 by Mariusz Felisiak, 3 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

In c99aaf14:

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

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 3 years ago

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