Merge pull request #2227 from Suor/optimize-isin

dvc: optmize PathInfo.isin()
This commit is contained in:
Ruslan Kuprieiev
2019-07-05 15:39:40 +03:00
committed by GitHub
+7 -1
View File
@@ -20,6 +20,10 @@ if is_py2:
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):
@@ -58,7 +62,9 @@ class PathInfo(pathlib.PurePath):
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.