From c38551b62c658101f5d0b6fc5810cff3dfb520f9 Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Thu, 4 Jul 2019 14:27:48 -0700 Subject: [PATCH] path info: optimize isin --- dvc/path_info.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dvc/path_info.py b/dvc/path_info.py index 657d7762f..d16b452e4 100644 --- a/dvc/path_info.py +++ b/dvc/path_info.py @@ -57,7 +57,11 @@ class PathInfo(pathlib.PurePath): other = self.__class__(other) elif self.__class__ != other.__class__: return False - return any(p == other for p in self.parents) + for p in self.parents: + if p == other: + return True + if len(other.parts) >= len(p.parts): + return False # pathlib2 uses bytes internally in Python 2, and we use unicode everywhere # for paths in both pythons, thus we need this glue.