Get rid of the second deepcopy for config values

There were two reasons why we deepcopy mutable objects in the config:

1) So mutations don't mess with our internal/default values.
2) So we can detect mutations and update the config.

If we're going to copy the value for 1) in maybe_copy(), we know the original
value is not going to be mutated, so we can use that directly for self._mutables
instead of making another copy.
This commit is contained in:
Florian Bruhin 2018-02-19 07:14:48 +01:00
parent 93972ff3f1
commit bd6e99158e

View File

@ -352,13 +352,13 @@ class Config(QObject):
return obj
value = self._values[name].get_for_pattern(pattern)
value = self._maybe_copy(value)
copy_value = self._maybe_copy(value)
# Watch the returned object for changes if it's mutable.
if isinstance(value, self.MUTABLE_TYPES):
self._mutables[name] = (copy.deepcopy(value), value)
if isinstance(copy_value, self.MUTABLE_TYPES):
self._mutables[name] = (value, copy_value) # old, new
return value
return copy_value
def get_str(self, name, *, pattern=None):
"""Get the given setting as string.