Skip to content

Commit

Permalink
Improve performance of sort helper function
Browse files Browse the repository at this point in the history
We save quite some time by not generating a list for the dict even if
the dict has only one entry.
  • Loading branch information
lucc committed Nov 17, 2023
1 parent ea976f9 commit b2d767e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions khard/carddav_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def multi_property_key(item: str) -> Tuple[Literal[0], str]: ...
def multi_property_key(item: Dict[T, Any]) -> Tuple[Literal[1], T]: ...
def multi_property_key(item: Union[str, Dict[T, Any]]
) -> Tuple[int, Union[T, str]]:
"""key function to pass to sorted(), allowing sorting of dicts with lists
"""Key function to pass to sorted(), allowing sorting of dicts with lists
and strings. Dicts will be sorted by their label, after other types.
:param item: member of the list being sorted
Expand All @@ -50,7 +50,7 @@ def multi_property_key(item: Union[str, Dict[T, Any]]
is not a dict.
"""
if isinstance(item, dict):
return (1, list(item)[0])
return (1, next(iter(item)))
return (0, item)


Expand Down

0 comments on commit b2d767e

Please sign in to comment.