minor performance improvements
Changed a couple cases where the inner Rc object was cloned to use the Rc object instead
This commit is contained in:
parent
99c1c880b0
commit
456b08a205
|
@ -680,6 +680,18 @@ impl TryFrom<Value> for Type {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&Value> for Type {
|
||||||
|
type Error = Error;
|
||||||
|
|
||||||
|
fn try_from(value: &Value) -> Result<Self, Self::Error> {
|
||||||
|
let constant: Constant = value.try_into()?;
|
||||||
|
|
||||||
|
let constant_type = Type::from(&constant);
|
||||||
|
|
||||||
|
Ok(constant_type)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<Value> for Constant {
|
impl TryFrom<Value> for Constant {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
|
@ -691,6 +703,17 @@ impl TryFrom<Value> for Constant {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<&Value> for Constant {
|
||||||
|
type Error = Error;
|
||||||
|
|
||||||
|
fn try_from(value: &Value) -> Result<Self, Self::Error> {
|
||||||
|
match value {
|
||||||
|
Value::Con(constant) => Ok(constant.as_ref().clone()),
|
||||||
|
rest => Err(Error::NotAConstant(rest.clone())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<&Constant> for Type {
|
impl From<&Constant> for Type {
|
||||||
fn from(constant: &Constant) -> Self {
|
fn from(constant: &Constant) -> Self {
|
||||||
match constant {
|
match constant {
|
||||||
|
|
|
@ -279,7 +279,7 @@ impl DefaultFunction {
|
||||||
if args.is_empty() {
|
if args.is_empty() {
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let first = args[0].as_ref().clone();
|
let first = args[0].as_ref();
|
||||||
|
|
||||||
arg.expect_type(Type::List(Rc::new(first.try_into()?)))
|
arg.expect_type(Type::List(Rc::new(first.try_into()?)))
|
||||||
}
|
}
|
||||||
|
@ -675,9 +675,9 @@ impl DefaultFunction {
|
||||||
DefaultFunction::AppendString => match (args[0].as_ref(), args[1].as_ref()) {
|
DefaultFunction::AppendString => match (args[0].as_ref(), args[1].as_ref()) {
|
||||||
(Value::Con(string1), Value::Con(string2)) => {
|
(Value::Con(string1), Value::Con(string2)) => {
|
||||||
match (string1.as_ref(), string2.as_ref()) {
|
match (string1.as_ref(), string2.as_ref()) {
|
||||||
(Constant::String(arg1), Constant::String(arg2)) => Ok(Value::Con(
|
(Constant::String(arg1), Constant::String(arg2)) => {
|
||||||
Constant::String(format!("{arg1}{arg2}")).into(),
|
Ok(Value::Con(Constant::String(format!("{arg1}{arg2}")).into()))
|
||||||
)),
|
}
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -749,18 +749,14 @@ impl DefaultFunction {
|
||||||
},
|
},
|
||||||
DefaultFunction::FstPair => match args[0].as_ref() {
|
DefaultFunction::FstPair => match args[0].as_ref() {
|
||||||
Value::Con(pair) => match pair.as_ref() {
|
Value::Con(pair) => match pair.as_ref() {
|
||||||
Constant::ProtoPair(_, _, first, _) => {
|
Constant::ProtoPair(_, _, first, _) => Ok(Value::Con(first.clone())),
|
||||||
Ok(Value::Con(first.as_ref().clone().into()))
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
DefaultFunction::SndPair => match args[0].as_ref() {
|
DefaultFunction::SndPair => match args[0].as_ref() {
|
||||||
Value::Con(pair) => match pair.as_ref() {
|
Value::Con(pair) => match pair.as_ref() {
|
||||||
Constant::ProtoPair(_, _, _, second) => {
|
Constant::ProtoPair(_, _, _, second) => Ok(Value::Con(second.clone())),
|
||||||
Ok(Value::Con(second.as_ref().clone().into()))
|
|
||||||
}
|
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
},
|
},
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
|
Loading…
Reference in New Issue