Skip to content

Commit

Permalink
priv_paths nit: pre-sort table for common case
Browse files Browse the repository at this point in the history
It is most common that Path.cwd().is_relative_to( Path.home() ), i.e.
invocation of ctypesgen in a subdirectory of $HOME.
  • Loading branch information
mara004 committed Mar 17, 2024
1 parent 3b66ea6 commit ebd495b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ctypesgen/printer_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def paragraph_ctx(txt):
def get_priv_paths():
priv_paths = [(Path.home(), "~")]
if Path.cwd() != Path("/"): # don't strip unix root
priv_paths += [(Path.cwd(), ".")]
priv_paths.insert(0, (Path.cwd(), "."))
# sort descending by length to avoid interference
priv_paths.sort(key=lambda x: len(str(x[0])), reverse=True)
return priv_paths
Expand Down

0 comments on commit ebd495b

Please sign in to comment.