summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVajrasky Kok <sky.kok@speaklikeaking.com>2013-12-07 16:54:50 +0800
committerBaptiste Mispelon <bmispelon@gmail.com>2013-12-07 17:19:29 +0100
commita7cf48a2b7878bf98879f2963ab9a7d0e6493d9a (patch)
treedb6a58a3b771cd345f21d90f253101214df31aa4
parent65faa84de3fd3f42e938301574cccdec1578657d (diff)
Fixed #21573 -- Improved performance of utils.text.normalize_newlines.
-rw-r--r--django/utils/text.py3
1 files changed, 2 insertions, 1 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index bb05afefc4..b29e125f03 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -24,6 +24,7 @@ capfirst = allow_lazy(capfirst, six.text_type)
# Set up regular expressions
re_words = re.compile(r'<.*?>|((?:\w[-\w]*|&.*?;)+)', re.U | re.S)
re_tag = re.compile(r'<(/)?([^ ]+?)(?:(\s*/)| .*?)?>', re.S)
+re_newlines = re.compile(r'\r\n|\r') # Used in normalize_newlines
def wrap(text, width):
@@ -249,7 +250,7 @@ get_text_list = allow_lazy(get_text_list, six.text_type)
def normalize_newlines(text):
- return force_text(re.sub(r'\r\n|\r|\n', '\n', text))
+ return force_text(re_newlines.sub('\n', text))
normalize_newlines = allow_lazy(normalize_newlines, six.text_type)