• Niels Thykier's avatar
    Replace most calls to "map" with comprehensions · 6e24f59a
    Niels Thykier authored
    They are compatible with python2 + python3 and the 2to3 rewrite will
    do a similar transformation.  However, with this rewrite, we can
    improve the generated results a bit to avoid some suboptimal cases
    while also reducing the delta for the py2 and py3 variants of dak.
    
    As an example:
        filelist = []
        for ... in ...:
            filelist += map(lambda x: os.path.join(r, x),
                             filter(lambda x: x.endswith('.changes'), f))
    
    Here 2to3 offers the following rewrite:
    
        filelist = []
        for ... in ...:
            filelist += [os.path.join(r, x) for x in [x for x in f if x.endswith('.changes')]]
    
    But this is performance-wise much better written as:
    
         filelist = []
         for ... in ...:
             filelist.extend(os.path.join(r, x) for x in f if x.endswith('.changes'))
    
    The original code and the 2to3 variant produces a lot of temporary
    lists only to discard them again (in python2 filter + map generates a
    list each).  In the optimized variant, we avoid all the temporary
    lists by using a generator-comprehension.
    Signed-off-by: Niels Thykier's avatarNiels Thykier <niels@thykier.net>
    6e24f59a