diff options
author | Vincent Ambo <mail@tazj.in> | 2022-08-24T15·31+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2022-09-02T13·36+0000 |
commit | c3b13416b02d8e0e68330408b107d3aad29e3a3f (patch) | |
tree | b5c11048eacd1f1af86798e4e885b5e114fcf6e8 /tvix/eval/src/value/attrs.rs | |
parent | 86b21f9c330a6cb92bf62f26f7d066c75f1cefd6 (diff) |
refactor(tvix/eval): add NixAttrs::contains function r/4597
This avoids copying around the value more than needed. Change-Id: I35949d16dad7fb8f76e0f641eaccf48322144777 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6263 Tested-by: BuildkiteCI Reviewed-by: sterni <sternenseemann@systemli.org>
Diffstat (limited to 'tvix/eval/src/value/attrs.rs')
-rw-r--r-- | tvix/eval/src/value/attrs.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tvix/eval/src/value/attrs.rs b/tvix/eval/src/value/attrs.rs index 4109691992ca..bbff79fc0d1a 100644 --- a/tvix/eval/src/value/attrs.rs +++ b/tvix/eval/src/value/attrs.rs @@ -66,6 +66,14 @@ impl AttrsRep { AttrsRep::Map(map) => map.get(&key.into()), } } + + fn contains(&self, key: &str) -> bool { + match self { + AttrsRep::Empty => false, + AttrsRep::KV { .. } => key == "name" || key == "value", + AttrsRep::Map(map) => map.contains_key(&key.into()), + } + } } #[repr(transparent)] @@ -202,6 +210,10 @@ impl NixAttrs { self.0.select(key) } + pub fn contains(&self, key: &str) -> bool { + self.0.contains(key) + } + /// Implement construction logic of an attribute set, to encapsulate /// logic about attribute set optimisations inside of this module. pub fn construct(count: usize, mut stack_slice: Vec<Value>) -> EvalResult<Self> { |