Skip to content

Commit

Permalink
Merge pull request iterative#2227 from Suor/optimize-isin
Browse files Browse the repository at this point in the history
dvc: optmize PathInfo.isin()
  • Loading branch information
efiop authored Jul 5, 2019
2 parents 36f72cb + c4836b4 commit 3840435
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dvc/path_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@


class PathInfo(pathlib.PurePath):
# Use __slots__ in PathInfo objects following PurePath implementation.
# This makes objects smaller and speeds up attribute access.
# We don't add any fields so it's empty.
__slots__ = ()
scheme = "local"

def __new__(cls, *args):
Expand Down Expand Up @@ -58,7 +62,9 @@ def isin(self, other):
other = self.__class__(other)
elif self.__class__ != other.__class__:
return False
return any(p == other for p in self.parents)
# Use cached casefolded parts to compare paths
n = len(other._cparts)
return len(self._cparts) > n and self._cparts[:n] == other._cparts

# pathlib2 uses bytes internally in Python 2, and we use unicode everywhere
# for paths in both pythons, thus we need this glue.
Expand Down

0 comments on commit 3840435

Please sign in to comment.