diff --git a/dvc/path_info.py b/dvc/path_info.py index 657d7762f..ae4fa821a 100644 --- a/dvc/path_info.py +++ b/dvc/path_info.py @@ -19,6 +19,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): @@ -57,7 +61,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.