Commit 1109475b authored by Xavier Thompson's avatar Xavier Thompson

[opti] Remove redundant deepcopies

parent f365475e
......@@ -2042,41 +2042,30 @@ def _dists_sig(dists):
def _update_section(in1, s2):
s1 = copy.deepcopy(in1)
# Base section 2 on section 1; section 1 is copied, with key-value pairs
# in section 2 overriding those in section 1. If there are += or -=
# operators in section 2, process these to add or subtract items (delimited
# by newlines) from the preexisting values.
s2 = copy.deepcopy(s2) # avoid mutating the second argument, which is unexpected
# Sort on key, then on the addition or subtraction operator (+ comes first)
for k, v in sorted(s2.items(), key=lambda x: (x[0].rstrip(' +'), x[0][-1])):
# in section 2 overriding those in section 1.
# If there are += or -= operators in s2, process these to add or subtract
# items (delimited by newlines) from the preexisting values.
# Sort on key, then on + and - operators, so that KEY < KEY + < KEY -, to
# process them in this order if several are defined in the same section.
keysort = lambda x: (x[0].rstrip(' +'), x[0].endswith('+'))
for k, v in sorted(s2.items(), key=keysort):
if k.endswith('+'):
key = k.rstrip(' +')
implicit_value = SectionKey("", "IMPLICIT_VALUE")
# Find v1 in s2 first; it may have been defined locally too.
section_key = s2.get(key, s1.get(key, implicit_value))
section_key = copy.deepcopy(section_key)
section_key.addToValue(v.value, v.source)
s2[key] = section_key
del s2[k]
value = s1.get(key, SectionKey("", "IMPLICIT_VALUE"))
value.addToValue(v.value, v.source)
s1[key] = value
elif k.endswith('-'):
key = k.rstrip(' -')
implicit_value = SectionKey("", "IMPLICIT_VALUE")
# Find v1 in s2 first; it may have been set by a += operation first
section_key = s2.get(key, s1.get(key, implicit_value))
section_key = copy.deepcopy(section_key)
section_key.removeFromValue(v.value, v.source)
s2[key] = section_key
del s2[k]
_update_verbose(s1, s2)
return s1
def _update_verbose(s1, s2):
for key, v2 in s2.items():
if key in s1:
v1 = s1[key]
v1.overrideValue(v2)
value = s1.get(key, SectionKey("", "IMPLICIT_VALUE"))
value.removeFromValue(v.value, v.source)
s1[key] = value
else:
s1[key] = copy.deepcopy(v2)
if k in s1:
v1 = s1[k]
v1.overrideValue(v)
else:
s1[k] = v
return s1
def _update(in1, d2):
d1 = copy.deepcopy(in1)
......
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