From: Brian Wellington Date: Tue, 8 Sep 2020 18:01:57 +0000 (-0700) Subject: Simplify code. X-Git-Tag: v2.1.0rc1~17^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6fb7434511a9b244a960193fc33174c7c6bab172;p=thirdparty%2Fdnspython.git Simplify code. --- diff --git a/dns/rdtypes/util.py b/dns/rdtypes/util.py index ddc4c672..695754df 100644 --- a/dns/rdtypes/util.py +++ b/dns/rdtypes/util.py @@ -15,6 +15,7 @@ # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +import collections import random import struct @@ -187,20 +188,16 @@ class Bitmap: def _priority_table(items): - by_priority = {} + by_priority = collections.defaultdict(list) for rdata in items: key = rdata._processing_priority() - rdatas = by_priority.get(key) - if rdatas is None: - rdatas = [] - by_priority[key] = rdatas - rdatas.append(rdata) + by_priority[rdata._processing_priority()].append(rdata) return by_priority def priority_processing_order(iterable): items = list(iterable) if len(items) == 1: - return [items[0]] + return items by_priority = _priority_table(items) ordered = [] for k in sorted(by_priority.keys()): @@ -219,7 +216,7 @@ def _processing_weight(rdata, adjust_zero_weight): def weighted_processing_order(iterable, adjust_zero_weight=False): items = list(iterable) if len(items) == 1: - return [items[0]] + return items by_priority = _priority_table(items) ordered = [] for k in sorted(by_priority.keys()):