Browse Source

perf: Avoid creating an intermediate container

create a items tuple by combining first_items with extra_items and is not used in the reminder of the code.
To make it more efficient we can check the items directly
pull/14233/head
Arun Prasad 9 months ago
parent
commit
f8f19b1a74
  1. 5
      fastapi/utils.py

5
fastapi/utils.py

@ -247,8 +247,9 @@ def get_value_or_default(
Otherwise, the first item (a `DefaultPlaceholder`) will be returned. Otherwise, the first item (a `DefaultPlaceholder`) will be returned.
""" """
items = (first_item,) + extra_items if not isinstance(first_item, DefaultPlaceholder):
for item in items: return first_item
for item in extra_items:
if not isinstance(item, DefaultPlaceholder): if not isinstance(item, DefaultPlaceholder):
return item return item
return first_item return first_item

Loading…
Cancel
Save