From 6dc9ca5723ee46ade3ad3618ae780ec88ae884e2 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 10 Aug 2022 17:53:22 +0300 Subject: feat(tvix/value): introduce string representation with &'static str For cases where the strings are statically known (such as the oft-occuring name/value), this can be a useful optimisation. It's also much more convenient in tests. Change-Id: Ie462b684805bd4986ea5e85ca4bff663bc2d3c3c Reviewed-on: https://cl.tvl.fyi/c/depot/+/6111 Tested-by: BuildkiteCI Reviewed-by: eta --- tvix/eval/src/compiler.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'tvix/eval/src/compiler.rs') diff --git a/tvix/eval/src/compiler.rs b/tvix/eval/src/compiler.rs index 5b6f748dc7..668ec842e8 100644 --- a/tvix/eval/src/compiler.rs +++ b/tvix/eval/src/compiler.rs @@ -111,7 +111,7 @@ impl Compiler { rnix::StrPart::Ast(node) => self.compile(node)?, rnix::StrPart::Literal(lit) => { - let idx = self.chunk.add_constant(Value::String(NixString(lit))); + let idx = self.chunk.add_constant(Value::String(lit.into())); self.chunk.add_op(OpCode::OpConstant(idx)); } } @@ -206,9 +206,9 @@ impl Compiler { let ident = rnix::types::Ident::cast(fragment).unwrap(); // TODO(tazjin): intern! - let idx = self - .chunk - .add_constant(Value::String(NixString(ident.as_str().to_string()))); + let idx = self.chunk.add_constant(Value::String(NixString::Heap( + ident.as_str().to_string(), + ))); self.chunk.add_op(OpCode::OpConstant(idx)); } -- cgit 1.4.1