From c91d86ee5ccada2c3868170f263be2b3d396d759 Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Tue, 18 Oct 2022 22:31:30 -0700 Subject: feat(tvix/eval): NixList::concat(): avoid an unnecessary move 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> for lists longer than a certain length. Signed-off-by: Adam Joseph Change-Id: I32154d18785a1f663454a8b9d4afd3e78bffdf9c Reviewed-on: https://cl.tvl.fyi/c/depot/+/7040 Tested-by: BuildkiteCI Reviewed-by: tazjin --- tvix/eval/src/value/list.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'tvix') 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 { -- cgit 1.4.1