summaryrefslogtreecommitdiff
path: root/django/utils/encoding.py
diff options
context:
space:
mode:
authorJannis Leidel <jannis@leidel.info>2010-09-27 15:25:08 +0000
committerJannis Leidel <jannis@leidel.info>2010-09-27 15:25:08 +0000
commit534792d05591eb2d19dc48ee89dcd2d9b5d461c0 (patch)
treef5e2fcd19541726fe51fc7c9507300733053b1da /django/utils/encoding.py
parent9c402f0ecc3751a746cc0aeaa24b7b8320af70f7 (diff)
Fixed #14290 -- Made format localization faster by caching the format modules. Thanks, Teemu Kurppa and Anssi Kääriäinen for the report and initial patches.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@13898 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils/encoding.py')
-rw-r--r--django/utils/encoding.py5
1 files changed, 5 insertions, 0 deletions
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index e2d7249903..9301419b5c 100644
--- a/django/utils/encoding.py
+++ b/django/utils/encoding.py
@@ -58,6 +58,11 @@ def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
If strings_only is True, don't convert (some) non-string-like objects.
"""
+ # Handle the common case first, saves 30-40% in performance when s
+ # is an instance of unicode. This function gets called often in that
+ # setting.
+ if isinstance(s, unicode):
+ return s
if strings_only and is_protected_type(s):
return s
try: