summaryrefslogtreecommitdiff
path: root/django/utils/text.py
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2021-03-23 09:45:58 +0000
committerGitHub <noreply@github.com>2021-03-23 10:45:58 +0100
commit6efc35b4fe3009666e56a60af0675d7d532bf4ff (patch)
tree73a67559d15944bfd52d74a5750559c5d7645c4a /django/utils/text.py
parent2cd40263348a9c345a58c44d48922ac3b370a119 (diff)
downloaddjango-6efc35b4fe3009666e56a60af0675d7d532bf4ff.tar.gz
Optimized django.utils.text.capfirst().
Unconditionally coercing to str type twice is expensive.
Diffstat (limited to 'django/utils/text.py')
-rw-r--r--django/utils/text.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/django/utils/text.py b/django/utils/text.py
index 2b1be6c2b1..7cc388f7fe 100644
--- a/django/utils/text.py
+++ b/django/utils/text.py
@@ -12,7 +12,11 @@ from django.utils.translation import gettext as _, gettext_lazy, pgettext
@keep_lazy_text
def capfirst(x):
"""Capitalize the first letter of a string."""
- return x and str(x)[0].upper() + str(x)[1:]
+ if not x:
+ return x
+ if not isinstance(x, str):
+ x = str(x)
+ return x[0].upper() + x[1:]
# Set up regular expressions