Don't reset the cache on pop if no deletion occurs

When the stack is being pop'd, it is not necessary to reset it if no
variable is either reset to its previous value or deleted.
This commit is contained in:
Emmanuel BENOîT 2022-09-18 12:12:23 +02:00
parent 91a90def13
commit f42df48a1b

View file

@ -161,16 +161,18 @@ class VariableStorage(MutableMapping):
restored. The cache will be reset.
"""
restore = self._script_stack.pop()
if not restore:
return
unchanged = 0
for vn, vv in restore.items():
existed, value = vv
if existed:
self._script_vars[vn] = value
elif vn in self._script_vars:
del self._script_vars[vn]
self._cache = self._host_vars.copy()
self._cache.update(self._script_vars)
else:
unchanged += 1
if unchanged != len(restore):
self._cache = self._host_vars.copy()
self._cache.update(self._script_vars)
def _set_host_var(self, name, value):
"""Set a host variable.