#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.b978e99a8bae73b19d70d006c2104ca9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to