summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-11-01 12:40:57 +0000
committerDaniel Silverstone <daniel.silverstone@codethink.co.uk>2018-11-01 13:40:24 +0000
commitd868b409c66e788c1f6f0ad551573a5d72bc8a28 (patch)
treececc6345b157c118c47819cdfa218a2a775aedb9
parent48860aacdd619a1d8692dcb39919a58a3a6d2349 (diff)
downloadbuildstream-d868b409c66e788c1f6f0ad551573a5d72bc8a28.tar.gz
_yaml.py: Implement `get()` for `ChainMap`
Since the core Python `ChainMap.get()` implements with: self[key] if key in self else default The double-chain-lookup is expensive. This simple change solves that for our ChainMap derived structure. As such it improves matters for #466 somewhat. Signed-off-by: Daniel Silverstone <daniel.silverstone@codethink.co.uk>
-rw-r--r--buildstream/_yaml.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/buildstream/_yaml.py b/buildstream/_yaml.py
index ca12acae9..f44572ca5 100644
--- a/buildstream/_yaml.py
+++ b/buildstream/_yaml.py
@@ -1049,6 +1049,12 @@ class ChainMap(collections.ChainMap):
for key in clearable:
del self[key]
+ def get(self, key, default=None):
+ try:
+ return self[key]
+ except KeyError:
+ return default
+
def node_chain_copy(source):
copy = ChainMap({}, source)