[Django] #24221: Use compiled regular expression when checking success_url

16 views
Skip to first unread message

Django

unread,
Jan 26, 2015, 5:21:04 AM1/26/15
to django-...@googlegroups.com
#24221: Use compiled regular expression when checking success_url
--------------------------------------+------------------------
Reporter: tricoder42 | Owner: tricoder42
Type: Cleanup/optimization | Status: new
Component: Generic views | Version: 1.8alpha1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------
While working on #24220 I also noticed that old-style formatting is
checked using `re.search` with inline regexp. Wouldn't it be better to
compile regexp pattern in advance at top level? I don't know the real
performance gain, but using precompiled regexp where possible is common
sense to me.

{{{
if re.search(r'%\([^\)]+\)', self.success_url):
}}}

replace with:

{{{
percent_placeholder = re.compile(r'%\([^\)]+\)')

...

def get_success_url():
if percent_placeholder.search(self.success_url):
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24221>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 26, 2015, 5:25:24 AM1/26/15
to django-...@googlegroups.com
#24221: Use compiled regular expression when checking success_url
-------------------------------------+-------------------------------------
Reporter: tricoder42 | Owner:
Type: | tricoder42
Cleanup/optimization | Status: assigned

Component: Generic views | Version: 1.8alpha1
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by tricoder42):

* status: new => assigned
* needs_better_patch: => 0
* has_patch: 0 => 1
* needs_tests: => 0
* needs_docs: => 0


Comment:

Added PR https://github.com/django/django/pull/3990

--
Ticket URL: <https://code.djangoproject.com/ticket/24221#comment:1>

Django

unread,
Jan 26, 2015, 10:49:08 AM1/26/15
to django-...@googlegroups.com
#24221: Use compiled regular expression when checking success_url
-------------------------------------+-------------------------------------
Reporter: tricoder42 | Owner:
Type: | tricoder42
Cleanup/optimization | Status: closed

Component: Generic views | Version: 1.8alpha1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"ea0ea7859a224225950a4df7c23eb3a7d823ddcd"]:
{{{
#!CommitTicketReference repository=""
revision="ea0ea7859a224225950a4df7c23eb3a7d823ddcd"
Fixed #24221 - Used precompiled regexp for percent-placeholder matching.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24221#comment:2>

Django

unread,
Jan 26, 2015, 10:50:17 AM1/26/15
to django-...@googlegroups.com
#24221: Use compiled regular expression when checking success_url
-------------------------------------+-------------------------------------
Reporter: tricoder42 | Owner:
Type: | tricoder42
Cleanup/optimization | Status: closed
Component: Generic views | Version: 1.8alpha1
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"2d990fb7fa6a04bb709aa9d7f687ec009c557c9e"]:
{{{
#!CommitTicketReference repository=""
revision="2d990fb7fa6a04bb709aa9d7f687ec009c557c9e"
[1.8.x] Fixed #24221 - Used precompiled regexp for percent-placeholder
matching.

Backport of ea0ea7859a224225950a4df7c23eb3a7d823ddcd from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/24221#comment:3>

Reply all
Reply to author
Forward
0 new messages