Commit 126e3528 authored by Xavier Thompson's avatar Xavier Thompson

[opti] Update sections in-place

This avoids unecessary deepcopies. This is a preparatory step to
reimplementing the extends algorithm. It may be that this breaks
the extends algorithm as it is currently implemented.
parent 0d565b56
......@@ -1592,7 +1592,7 @@ class Options(DictMixin):
result = _annotate_section(result, "")
data = _annotate_section(copy.deepcopy(data), "")
result = _update_section(result, data)
_update_section(result, data)
result = _unannotate_section(result)
result.pop('<', None)
return result
......@@ -2031,14 +2031,13 @@ def _dists_sig(dists):
result.append(os.path.basename(location))
return result
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.
def _update_section(s1, s2):
# Base section 2 on section 1; key-value pairs in s2 override those in s1.
# 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.
# 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('+'):
......@@ -2059,13 +2058,12 @@ def _update_section(in1, s2):
s1[k] = v
return s1
def _update(in1, d2):
d1 = copy.deepcopy(in1)
def _update(d1, d2):
for section in d2:
if section in d1:
d1[section] = _update_section(d1[section], d2[section])
_update_section(d1[section], d2[section])
else:
d1[section] = copy.deepcopy(d2[section])
d1[section] = d2[section]
return d1
def _recipe(options):
......
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