From 2fa592576b376d7d233d781bfdd474c7accc2219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Mon, 13 Apr 2020 22:09:43 +0200 Subject: [PATCH] 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. --- src/ast.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/ast.rs b/src/ast.rs index b0e53e3..785947e 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -170,14 +170,14 @@ pub struct Function impl Function { - pub fn new(declaration: &std::rc::Rc, arguments: Vec>) -> Self + pub fn new(declaration: std::rc::Rc, arguments: Vec>) -> Self { assert_eq!(declaration.arity, arguments.len(), "function has a different number of arguments then declared"); Self { - declaration: std::rc::Rc::clone(declaration), + declaration, arguments, } } @@ -215,11 +215,11 @@ pub struct Variable impl Variable { - pub fn new(declaration: &std::rc::Rc) -> Self + pub fn new(declaration: std::rc::Rc) -> Self { Self { - declaration: std::rc::Rc::clone(declaration), + declaration, } } } @@ -293,14 +293,14 @@ pub struct Predicate impl Predicate { - pub fn new(declaration: &std::rc::Rc, arguments: Vec>) -> Self + pub fn new(declaration: std::rc::Rc, arguments: Vec>) -> Self { assert_eq!(declaration.arity, arguments.len(), "predicate has a different number of arguments then declared"); Self { - declaration: std::rc::Rc::clone(declaration), + declaration, arguments, } } @@ -359,7 +359,7 @@ impl Term Self::boolean(false) } - pub fn function(declaration: &std::rc::Rc, arguments: Vec>) + pub fn function(declaration: std::rc::Rc, arguments: Vec>) -> Self { Self::Function(Function::new(declaration, arguments)) @@ -420,7 +420,7 @@ impl Term Self::UnaryOperation(UnaryOperation::new(operator, argument)) } - pub fn variable(declaration: &std::rc::Rc) -> Self + pub fn variable(declaration: std::rc::Rc) -> Self { Self::Variable(Variable::new(declaration)) } @@ -533,7 +533,7 @@ impl Formula Self::Or(arguments) } - pub fn predicate(declaration: &std::rc::Rc, arguments: Vec>) + pub fn predicate(declaration: std::rc::Rc, arguments: Vec>) -> Self { Self::Predicate(Predicate::new(declaration, arguments))