diff options
author | Adam Joseph <adam@westernsemico.com> | 2022-10-19T05·31-0700 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2022-10-19T10·37+0000 |
commit | c91d86ee5ccada2c3868170f263be2b3d396d759 (patch) | |
tree | 7f575f56ce842b6fa7402a44f66b7459c081337d | |
parent | 4b01e594d5d5cb806f6fe6eef1c30069748369cd (diff) |
feat(tvix/eval): NixList::concat(): avoid an unnecessary move r/5158
In `a++b`, the previous implementation would move `b` (i.e. memcpy its elements) twice. Let's do that only once. We sure do call NixList.clone() a whole lot. At some point in the future we probably want to do a SmolStr-type split for NixList into a two-variant enum where one side is an Rc<Vec<Value>> for lists longer than a certain length. Signed-off-by: Adam Joseph <adam@westernsemico.com> Change-Id: I32154d18785a1f663454a8b9d4afd3e78bffdf9c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7040 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
-rw-r--r-- | tvix/eval/src/value/list.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/tvix/eval/src/value/list.rs b/tvix/eval/src/value/list.rs index 486b0c3fca76..3be5d414572c 100644 --- a/tvix/eval/src/value/list.rs +++ b/tvix/eval/src/value/list.rs @@ -50,10 +50,9 @@ mod arbitrary { impl NixList { pub fn concat(&self, other: &Self) -> Self { - let mut lhs = self.clone(); - let mut rhs = other.clone(); - lhs.0.append(&mut rhs.0); - lhs + let mut ret = self.clone(); + ret.0.extend_from_slice(&other.0); + ret } pub fn len(&self) -> usize { |