paulc / dnslib

A Python library to encode/decode DNS wire-format packets
https://github.com/paulc/dnslib
BSD 2-Clause "Simplified" License
295 stars 84 forks source link

Use chain.from_iterable in dns.py #13

Closed cool-RR closed 3 years ago

cool-RR commented 4 years ago

This is a faster and more idiomatic way of using itertools.chain. Instead of computing all the items in the iterable and storing them in memory, they are computed one-by-one and never stored as a huge list. This can save on both runtime and memory space.

cool-RR commented 4 years ago

@paulc What do you think?

paulc commented 4 years ago

HI, thanks for the patch, this isn't actually faster (tested with timeit - the maximum length of the list is 8 items) but it is a bit neater so will look to incorporate next time I do an update.