Commit 52198b81 authored by Xavier Thompson's avatar Xavier Thompson

[fix/opti] Fix "Remove redundant deepcopies"

Also, remove more redundant deepcopies
parent 9d6659c6
...@@ -2275,35 +2275,30 @@ def _dists_sig(dists): ...@@ -2275,35 +2275,30 @@ def _dists_sig(dists):
return result return result
def _update_section(s1, s2): def _update_section(s1, s2):
# Base section 2 on section 1; section 1 is copied, with key-value pairs # Base section 2 on section 1; key-value pairs in s2 override those in s1.
# in section 2 overriding those in section 1. If there are += or -= # If there are += or -= operators in s2, process these to add or subtract
# operators in section 2, process these to add or subtract items (delimited # items (delimited by newlines) from the preexisting values.
# by newlines) from the preexisting values. # Sort on key, then on + and - operators, so that KEY < KEY + < KEY -, to
# Sort on key, then on the addition or subtraction operator (+ comes first) # process them in this order if several are defined in the same section.
for k, v in sorted(s2.items(), key=lambda x: (x[0].rstrip(' +'), x[0][-1])): # Section s1 is modified in place.
keysort = lambda x: (x[0].rstrip(' +'), x[0].endswith('+'))
for k, v in sorted(s2.items(), key=keysort):
if k.endswith('+'): if k.endswith('+'):
key = k.rstrip(' +') key = k.rstrip(' +')
implicit_value = SectionKey("", "IMPLICIT_VALUE") value = s1.get(key, SectionKey("", "IMPLICIT_VALUE"))
# Find v1 in s2 first; it may have been defined locally too. value.addToValue(v.value, v.source)
section_key = s2.get(key, s1.get(key, implicit_value)) s1[key] = value
section_key = copy.deepcopy(section_key)
section_key.addToValue(v.value, v.source)
elif k.endswith('-'): elif k.endswith('-'):
key = k.rstrip(' -') key = k.rstrip(' -')
implicit_value = SectionKey("", "IMPLICIT_VALUE") value = s1.get(key, SectionKey("", "IMPLICIT_VALUE"))
# Find v1 in s2 first; it may have been set by a += operation first value.removeFromValue(v.value, v.source)
section_key = s2.get(key, s1.get(key, implicit_value)) s1[key] = value
section_key = copy.deepcopy(section_key)
section_key.removeFromValue(v.value, v.source)
else: else:
key = k if k in s1:
section_key = v v1 = s1[k]
v1.overrideValue(v)
if key in s1: else:
v1 = s1[key] s1[k] = v
v1.overrideValue(section_key)
else:
s1[key] = section_key
return s1 return s1
def _update(d1, d2): def _update(d1, d2):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment