feat(value): less clone
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
use std::collections::HashSet;
|
||||
|
||||
use derive_more::Constructor;
|
||||
use rpds::VectorSync;
|
||||
use rpds::Vector;
|
||||
|
||||
use crate::error::Result;
|
||||
use crate::ty::public as p;
|
||||
use crate::vm::VM;
|
||||
|
||||
use super::{ToPublic, Value};
|
||||
use super::Value;
|
||||
|
||||
#[derive(Debug, Constructor, Clone, PartialEq)]
|
||||
pub struct List<'vm> {
|
||||
data: VectorSync<Value<'vm>>,
|
||||
data: Vector<Value<'vm>>,
|
||||
}
|
||||
|
||||
impl<'vm> List<'vm> {
|
||||
pub fn empty() -> Self {
|
||||
List {
|
||||
data: VectorSync::new_sync(),
|
||||
data: Vector::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,30 +25,26 @@ impl<'vm> List<'vm> {
|
||||
self.data.push_back_mut(elem);
|
||||
}
|
||||
|
||||
pub fn concat(mut self, other: List<'vm>) -> List<'vm> {
|
||||
pub fn concat(&mut self, other: &List<'vm>) {
|
||||
for elem in other.data.iter() {
|
||||
self.data.push_back_mut(elem.clone());
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
pub fn force_deep(&mut self, vm: &'vm VM<'_>) -> Result<()> {
|
||||
let mut vec: Vec<_> = self.data.iter().cloned().collect();
|
||||
vec.iter_mut()
|
||||
.map(|v| v.force_deep(vm).map(|_| ()))
|
||||
.find(|v| v.is_err())
|
||||
.map_or(Ok(()), |err| err)?;
|
||||
for v in vec.iter_mut() {
|
||||
v.force_deep(vm)?;
|
||||
}
|
||||
self.data = vec.into_iter().collect();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl ToPublic for List<'_> {
|
||||
fn to_public(self, vm: &VM) -> p::Value {
|
||||
pub fn to_public(&self, vm: &'vm VM, seen: &mut HashSet<Value<'vm>>) -> p::Value {
|
||||
p::Value::List(p::List::new(
|
||||
self.data
|
||||
.iter()
|
||||
.map(|value| value.clone().to_public(vm))
|
||||
.map(|value| value.clone().to_public(vm, seen))
|
||||
.collect(),
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user