about summary refs log tree commit diff
path: root/tvix
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-10-16T16·14+0100
committerclbot <clbot@tvl.fyi>2023-10-16T16·17+0000
commit73a19c249ef47cfdd55ebd8230cb9c0439beb749 (patch)
treee4b5e3e42b2fed6afeb80c2872768980fa3c2008 /tvix
parent7df720855d23a94ec1ed5de4b667391a2028581d (diff)
refactor(tvix/nix-compat/derivation): remove some clones r/6841
Change-Id: Ie464467edfafd2050aa9e5fd0e07ff745cb15df8
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9753
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Diffstat (limited to 'tvix')
-rw-r--r--tvix/nix-compat/src/derivation/parser.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/tvix/nix-compat/src/derivation/parser.rs b/tvix/nix-compat/src/derivation/parser.rs
index 2b5a8041592b..48f2b92d9168 100644
--- a/tvix/nix-compat/src/derivation/parser.rs
+++ b/tvix/nix-compat/src/derivation/parser.rs
@@ -134,7 +134,7 @@ fn parse_input_derivations(i: &[u8]) -> NomResult<&[u8], BTreeMap<String, BTreeS
     for (input_derivation, output_names) in input_derivations_list {
         let mut new_output_names = BTreeSet::new();
         for output_name in output_names.into_iter() {
-            if !new_output_names.insert(output_name.clone()) {
+            if new_output_names.contains(&output_name) {
                 return Err(nom::Err::Failure(NomError {
                     input: i,
                     code: ErrorKind::DuplicateInputDerivationOutputName(
@@ -142,6 +142,8 @@ fn parse_input_derivations(i: &[u8]) -> NomResult<&[u8], BTreeMap<String, BTreeS
                         output_name.to_string(),
                     ),
                 }));
+            } else {
+                new_output_names.insert(output_name);
             }
         }
         input_derivations.insert(input_derivation, new_output_names);
@@ -155,11 +157,13 @@ fn parse_input_sources(i: &[u8]) -> NomResult<&[u8], BTreeSet<String>> {
 
     let mut input_sources: BTreeSet<_> = BTreeSet::new();
     for input_source in input_sources_lst.into_iter() {
-        if !input_sources.insert(input_source.clone()) {
+        if input_sources.contains(&input_source) {
             return Err(nom::Err::Failure(NomError {
                 input: i,
                 code: ErrorKind::DuplicateInputSource(input_source),
             }));
+        } else {
+            input_sources.insert(input_source);
         }
     }
 
@@ -253,11 +257,13 @@ where
                     for (k, v) in pairs.into_iter() {
                         // collect the 2-tuple to a BTreeMap,
                         // and fail if the key was already seen before.
-                        if kvs.insert(k.clone(), v).is_some() {
+                        if kvs.contains_key(&k) {
                             return Err(nom::Err::Failure(NomError {
                                 input: i,
                                 code: ErrorKind::DuplicateMapKey(k),
                             }));
+                        } else {
+                            kvs.insert(k, v);
                         }
                     }
                     Ok((rest, kvs))