﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21573	Cache regular expression for normalizing newlines in django.utils.text.normalize_newlines	Vajrasky Kok	Vajrasky Kok	"This is the method:

{{{
def normalize_newlines(text):
    return force_text(re.sub(r'\r\n|\r|\n', '\n', text))
normalize_newlines = allow_lazy(normalize_newlines, six.text_type)
}}}


It should be:

{{{
_newlines_re = re.compile(r'\r\n|\r|\r')
def normalize_newlines(text):
    return force_text(_newlines_re.sub('\n', text))
normalize_newlines = allow_lazy(normalize_newlines, six.text_type)
}}}

Things to be considered:
* Do we use this method often in Django? If not, caching may not be necessary.
* From http://docs.python.org/2/library/re.html#re.compile: The compiled versions of the most recent patterns passed to re.match(), re.search() or re.compile() are cached, so programs that use only a few regular expressions at a time needn’t worry about compiling regular expressions.
* The performance gain maybe negligible."	Cleanup/optimization	closed	Utilities	dev	Normal	fixed	performance	sky.kok@…	Ready for checkin	1	0	0	0	1	0
