Commit 6b0ea6d0 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 25140175
...@@ -1586,7 +1586,7 @@ class Options(DictMixin): ...@@ -1586,7 +1586,7 @@ class Options(DictMixin):
result = _annotate_section(result, "") result = _annotate_section(result, "")
data = _annotate_section(copy.deepcopy(data), "") data = _annotate_section(copy.deepcopy(data), "")
result = _update_section(result, data) _update_section(result, data)
result = _unannotate_section(result) result = _unannotate_section(result)
result.pop('<', None) result.pop('<', None)
return result return result
...@@ -2025,14 +2025,13 @@ def _dists_sig(dists): ...@@ -2025,14 +2025,13 @@ def _dists_sig(dists):
result.append(os.path.basename(location)) result.append(os.path.basename(location))
return result return result
def _update_section(in1, s2): def _update_section(s1, s2):
s1 = copy.deepcopy(in1) # Base section 2 on section 1; key-value pairs in s2 override those in s1.
# 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 s2, process these to add or subtract # If there are += or -= operators in s2, process these to add or subtract
# items (delimited by newlines) from the preexisting values. # items (delimited by newlines) from the preexisting values.
# Sort on key, then on + and - operators, so that KEY < KEY + < KEY -, to # 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. # 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('+')) keysort = lambda x: (x[0].rstrip(' +'), x[0].endswith('+'))
for k, v in sorted(s2.items(), key=keysort): for k, v in sorted(s2.items(), key=keysort):
if k.endswith('+'): if k.endswith('+'):
...@@ -2053,13 +2052,12 @@ def _update_section(in1, s2): ...@@ -2053,13 +2052,12 @@ def _update_section(in1, s2):
s1[k] = v s1[k] = v
return s1 return s1
def _update(in1, d2): def _update(d1, d2):
d1 = copy.deepcopy(in1)
for section in d2: for section in d2:
if section in d1: if section in d1:
d1[section] = _update_section(d1[section], d2[section]) _update_section(d1[section], d2[section])
else: else:
d1[section] = copy.deepcopy(d2[section]) d1[section] = d2[section]
return d1 return d1
def _recipe(options): 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