From adf7353ae6f13256d415da5c7e61621b09c54901 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 28 Oct 2020 14:55:49 -0700 Subject: [PATCH] Cache _case_correct property to cut down on fs calls. --- voussoirkit/pathclass.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 20831c8..2fb9665 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -65,10 +65,12 @@ class Path: ''' I started to use pathlib.Path, but it was too much of a pain. ''' - def __init__(self, path, force_sep=None): + def __init__(self, path, force_sep=None, *, _case_correct=False): self.force_sep = force_sep self.sep = force_sep or os.sep + self._case_correct = _case_correct + if isinstance(path, Path): self.absolute_path = path.absolute_path else: @@ -136,8 +138,11 @@ class Path: return os.path.basename(self.absolute_path) def correct_case(self): + if self._case_correct: + return self self.absolute_path = get_path_casing(self.absolute_path) self.absolute_path = self.absolute_path.replace('/', self.sep).replace('\\', self.sep) + self._case_correct = True return self @property