Take reference-counted arguments by value
These reference-counted arguments were taken by reference, which made it necessary to clone them. If a reference-counted object is created for the sole purpose of being passed to one of these methods, it would be cloned unnecessarily. This changes the signatures to take these arguments by value, shifting the responsibility of cloning the reference-counted objects to the users of these methods.
This commit is contained in:
parent
7d22e47ba1
commit
2fa592576b
18
src/ast.rs
18
src/ast.rs
@ -170,14 +170,14 @@ pub struct Function
|
|||||||
|
|
||||||
impl Function
|
impl Function
|
||||||
{
|
{
|
||||||
pub fn new(declaration: &std::rc::Rc<FunctionDeclaration>, arguments: Vec<Box<Term>>) -> Self
|
pub fn new(declaration: std::rc::Rc<FunctionDeclaration>, arguments: Vec<Box<Term>>) -> Self
|
||||||
{
|
{
|
||||||
assert_eq!(declaration.arity, arguments.len(),
|
assert_eq!(declaration.arity, arguments.len(),
|
||||||
"function has a different number of arguments then declared");
|
"function has a different number of arguments then declared");
|
||||||
|
|
||||||
Self
|
Self
|
||||||
{
|
{
|
||||||
declaration: std::rc::Rc::clone(declaration),
|
declaration,
|
||||||
arguments,
|
arguments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -215,11 +215,11 @@ pub struct Variable
|
|||||||
|
|
||||||
impl Variable
|
impl Variable
|
||||||
{
|
{
|
||||||
pub fn new(declaration: &std::rc::Rc<VariableDeclaration>) -> Self
|
pub fn new(declaration: std::rc::Rc<VariableDeclaration>) -> Self
|
||||||
{
|
{
|
||||||
Self
|
Self
|
||||||
{
|
{
|
||||||
declaration: std::rc::Rc::clone(declaration),
|
declaration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -293,14 +293,14 @@ pub struct Predicate
|
|||||||
|
|
||||||
impl Predicate
|
impl Predicate
|
||||||
{
|
{
|
||||||
pub fn new(declaration: &std::rc::Rc<PredicateDeclaration>, arguments: Vec<Box<Term>>) -> Self
|
pub fn new(declaration: std::rc::Rc<PredicateDeclaration>, arguments: Vec<Box<Term>>) -> Self
|
||||||
{
|
{
|
||||||
assert_eq!(declaration.arity, arguments.len(),
|
assert_eq!(declaration.arity, arguments.len(),
|
||||||
"predicate has a different number of arguments then declared");
|
"predicate has a different number of arguments then declared");
|
||||||
|
|
||||||
Self
|
Self
|
||||||
{
|
{
|
||||||
declaration: std::rc::Rc::clone(declaration),
|
declaration,
|
||||||
arguments,
|
arguments,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -359,7 +359,7 @@ impl Term
|
|||||||
Self::boolean(false)
|
Self::boolean(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn function(declaration: &std::rc::Rc<FunctionDeclaration>, arguments: Vec<Box<Term>>)
|
pub fn function(declaration: std::rc::Rc<FunctionDeclaration>, arguments: Vec<Box<Term>>)
|
||||||
-> Self
|
-> Self
|
||||||
{
|
{
|
||||||
Self::Function(Function::new(declaration, arguments))
|
Self::Function(Function::new(declaration, arguments))
|
||||||
@ -420,7 +420,7 @@ impl Term
|
|||||||
Self::UnaryOperation(UnaryOperation::new(operator, argument))
|
Self::UnaryOperation(UnaryOperation::new(operator, argument))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn variable(declaration: &std::rc::Rc<VariableDeclaration>) -> Self
|
pub fn variable(declaration: std::rc::Rc<VariableDeclaration>) -> Self
|
||||||
{
|
{
|
||||||
Self::Variable(Variable::new(declaration))
|
Self::Variable(Variable::new(declaration))
|
||||||
}
|
}
|
||||||
@ -533,7 +533,7 @@ impl Formula
|
|||||||
Self::Or(arguments)
|
Self::Or(arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn predicate(declaration: &std::rc::Rc<PredicateDeclaration>, arguments: Vec<Box<Term>>)
|
pub fn predicate(declaration: std::rc::Rc<PredicateDeclaration>, arguments: Vec<Box<Term>>)
|
||||||
-> Self
|
-> Self
|
||||||
{
|
{
|
||||||
Self::Predicate(Predicate::new(declaration, arguments))
|
Self::Predicate(Predicate::new(declaration, arguments))
|
||||||
|
Loading…
Reference in New Issue
Block a user