diff options
Diffstat (limited to 'django/utils/encoding.py')
| -rw-r--r-- | django/utils/encoding.py | 5 |
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: |
