# HG changeset patch # User Paul Boddie # Date 1508684560 -7200 # Node ID 99fb5e99498cbe95f34d2e4932b574319a00f1f8 # Parent a6c69e29fcbd93b9e25743d5d903fa15b75d4650 Removed superfluous sort operation. Made convert_positions a plain function. Removed superfluous abs operation. Removed superfluous test against the start of the selection period. diff -r a6c69e29fcbd -r 99fb5e99498c vRecurrence.py --- a/vRecurrence.py Sun Oct 22 01:24:08 2017 +0200 +++ b/vRecurrence.py Sun Oct 22 17:02:40 2017 +0200 @@ -645,6 +645,16 @@ l.sort(cmp=fn) return l +def convert_positions(setpos): + + "Convert 'setpos' to 0-based indexes." + + l = [] + for pos in setpos: + index = pos < 0 and pos or pos - 1 + l.append(index) + return l + # Classes for producing instances from recurrence structures. class Selector: @@ -702,28 +712,15 @@ if self.selecting: return self.selecting.materialise_items(current, earliest, next, counter, setpos, inclusive) - elif earliest <= current: + else: return [current] - else: - return [] - - def convert_positions(self, setpos): - - "Convert 'setpos' to 0-based indexes." - - l = [] - for pos in setpos: - index = pos < 0 and pos or pos - 1 - l.append(index) - return l def select_positions(self, results, setpos): "Select in 'results' the 1-based positions given by 'setpos'." - results.sort() l = [] - for index in self.convert_positions(setpos): + for index in convert_positions(setpos): l.append(results[index]) return l @@ -851,7 +848,7 @@ # Find each of the given days. for value, index in sort_weekdays(self.args["values"], first_day, last_day): - offset = timedelta(7 * (abs(index) - 1)) + offset = timedelta(7 * (index - 1)) current = precision(to_tuple(get_first_day(first_day, value) + offset), DAYS) next = update(current, step)