# HG changeset patch # User Paul Boddie # Date 1444483094 -7200 # Node ID 9373e63a5e483bb238184823092d537cfc8d49bf # Parent 9c39e4cb3ecdc0a404617cd5c8ef6d1a9e3c2972# Parent e0fe30d7b8b13f2108857d313baa3dae2a1235fd Merged repeated identical operation performance improvements. diff -r 9c39e4cb3ecd -r 9373e63a5e48 optimiser.py --- a/optimiser.py Sat Oct 10 14:58:40 2015 +0200 +++ b/optimiser.py Sat Oct 10 15:18:14 2015 +0200 @@ -58,6 +58,9 @@ r, g, b = srgb return 1.0 - r, 1.0 - g, 1.0 - b +scaled_corners = map(scale, corners) +zipped_corners = zip(corners, scaled_corners) + # Colour distribution functions. def combination(rgb): @@ -76,8 +79,8 @@ # input colour. d = [] - for corner in corners: - rs, gs, bs = scale(corner) + for corner, scaled in zipped_corners: + rs, gs, bs = scaled # Obtain inverted channel values where corner channels are low; # obtain original channel values where corner channels are high. @@ -95,6 +98,9 @@ r, g, b = rgb return rgb, restore(invert(scale(rgb))) +bases = [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)] +base_complements = map(complements, bases) + def balance(d): """ @@ -103,7 +109,7 @@ """ d = dict([(value, f) for f, value in d]) - for primary, secondary in map(complements, [(0, 0, 0), (255, 0, 0), (0, 255, 0), (0, 0, 255)]): + for primary, secondary in base_complements: common = min(d[primary], d[secondary]) d[primary] -= common d[secondary] -= common