From 534792d05591eb2d19dc48ee89dcd2d9b5d461c0 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Mon, 27 Sep 2010 15:25:08 +0000 Subject: 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. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@13898 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/encoding.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'django/utils/encoding.py') 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: -- cgit v1.3