diff options
author | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-06-17 03:24:05 +0000 |
---|---|---|
committer | ben <ben@2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109> | 2002-06-17 03:24:05 +0000 |
commit | 6b72b10acde7061c1180a59d6eea3c0c20780683 (patch) | |
tree | 1284913e6d64c09994149f0da28551029b522731 /rdiff-backup/src/selection.py | |
parent | 30a98a1fa0d78837915e9b26b35c9abfd0783cf3 (diff) | |
download | rdiff-backup-6b72b10acde7061c1180a59d6eea3c0c20780683.tar.gz |
Many optimizations - up to 3x speed improvement
git-svn-id: http://svn.savannah.nongnu.org/svn/rdiff-backup/trunk@134 2b77aa54-bcbc-44c9-a7ec-4f6cf2b41109
Diffstat (limited to 'rdiff-backup/src/selection.py')
-rw-r--r-- | rdiff-backup/src/selection.py | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/rdiff-backup/src/selection.py b/rdiff-backup/src/selection.py index 4fee9ee..05436c1 100644 --- a/rdiff-backup/src/selection.py +++ b/rdiff-backup/src/selection.py @@ -94,7 +94,9 @@ class Select: self.starting_index = starting_index self.iter = self.iterate_starting_from(self.dsrpath, self.iterate_starting_from, sel_func) - else: self.iter = self.Iterate(self.dsrpath, self.Iterate, sel_func) + elif self.quoting_on: + self.iter = self.Iterate(self.dsrpath, self.Iterate, sel_func) + else: self.iter = self.Iterate_fast(self.dsrpath, sel_func) # only iterate parents if we are not starting from beginning self.iterate_parents = starting_index is not None and iterate_parents @@ -102,6 +104,52 @@ class Select: self.__iter__ = lambda: self return self + def Iterate_fast(self, dsrpath, sel_func): + """Like Iterate, but don't recur, saving time + + This is a bit harder to read than Iterate/iterate_in_dir, but + it should be faster because it only recurs to half as much + depth. It doesn't handle the quoting case. + + """ + def error_handler(exc, filename): + Log("Error initializing file %s/%s" % (dsrpath.path, filename), 2) + return None + + def diryield(dsrpath): + s = sel_func(dsrpath) + if s == 0: return + elif s == 1: + yield dsrpath + for filename in Robust.listrp(dsrpath): + new_dsrp = Robust.check_common_error(error_handler, + dsrpath.append, [filename]) + if new_dsrp: + if new_dsrp.isdir(): + for dsrp in diryield(new_dsrp): yield dsrp + elif sel_func(new_dsrp) == 1: yield new_dsrp + elif s == 2: + yielded_something = None + for filename in Robust.listrp(dsrpath): + new_dsrp = Robust.check_common_error(error_handler, + dsrpath.append, [filename]) + if new_dsrp: + if new_dsrp.isdir(): + for dsrp in diryield(new_dsrp): + if not yielded_something: + yielded_something = 1 + yield dsrpath + yield dsrp + elif sel_func(new_dsrp) == 1: + if not yielded_something: + yielded_something = 1 + yield dsrpath + yield new_dsrp + + if dsrpath.isdir(): + for dsrp in diryield(dsrpath): yield dsrp + elif sel_func(dsrpath) == 1: yield dsrpath + def Iterate(self, dsrpath, rec_func, sel_func): """Return iterator yielding dsrps in dsrpath |