From ebd495b1733b60132151154d6358fd1eb336a36a Mon Sep 17 00:00:00 2001 From: geisserml Date: Sun, 17 Mar 2024 16:52:58 +0100 Subject: [PATCH] priv_paths nit: pre-sort table for common case It is most common that Path.cwd().is_relative_to( Path.home() ), i.e. invocation of ctypesgen in a subdirectory of $HOME. --- src/ctypesgen/printer_python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ctypesgen/printer_python.py b/src/ctypesgen/printer_python.py index 9c77750..78fe9e3 100755 --- a/src/ctypesgen/printer_python.py +++ b/src/ctypesgen/printer_python.py @@ -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