mirror of
https://github.com/django/django.git
synced 2025-05-24 07:46:29 +00:00
Optimized django.utils.text.capfirst().
Unconditionally coercing to str type twice is expensive.
This commit is contained in:
parent
2cd4026334
commit
6efc35b4fe
@ -12,7 +12,11 @@ from django.utils.translation import gettext as _, gettext_lazy, pgettext
|
|||||||
@keep_lazy_text
|
@keep_lazy_text
|
||||||
def capfirst(x):
|
def capfirst(x):
|
||||||
"""Capitalize the first letter of a string."""
|
"""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
|
# Set up regular expressions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user