Commit 8689c23e authored by Jeff Smits's avatar Jeff Smits

Reviewed usage of clone(d)/to_owned

parent b9b975d1
...@@ -48,7 +48,7 @@ impl<'d, 'f: 'd> MutContext<'d, 'f> { ...@@ -48,7 +48,7 @@ impl<'d, 'f: 'd> MutContext<'d, 'f> {
.flat_map(|prims| prims.get(prim_name)) .flat_map(|prims| prims.get(prim_name))
.cloned() // ATermRef should be very cheap to clone .cloned() // ATermRef should be very cheap to clone
.next() .next()
.ok_or_else(|| Error::UndefinedPrimitive(prim_name.to_owned()))?; .ok_or_else(|| Error::UndefinedPrimitive(String::from(prim_name)))?;
self.stack_tracer.borrow_mut().push(prim_name); self.stack_tracer.borrow_mut().push(prim_name);
let result = eval_prim_ref(&prim_ref, self, sargs, targs, current); let result = eval_prim_ref(&prim_ref, self, sargs, targs, current);
if result.is_ok() { if result.is_ok() {
...@@ -68,7 +68,7 @@ impl<'d, 'f: 'd> MutContext<'d, 'f> { ...@@ -68,7 +68,7 @@ impl<'d, 'f: 'd> MutContext<'d, 'f> {
.flat_map(|scope| scope.strategy.get(strat_name)) .flat_map(|scope| scope.strategy.get(strat_name))
.cloned() // StrategyDef is fairly cheap to clone .cloned() // StrategyDef is fairly cheap to clone
.next() .next()
.ok_or_else(|| Error::UndefinedStrategy(strat_name.to_owned())) .ok_or_else(|| Error::UndefinedStrategy(String::from(strat_name)))
} }
pub fn get_term(&self, term_name: &str) -> Result<ATermRef<'f>> { pub fn get_term(&self, term_name: &str) -> Result<ATermRef<'f>> {
...@@ -281,7 +281,7 @@ pub mod Scopes { ...@@ -281,7 +281,7 @@ pub mod Scopes {
return Ok((n, binding.clone())); return Ok((n, binding.clone()));
} }
} }
Err(Error::UndefinedVariable(term_name.to_owned())) Err(Error::UndefinedVariable(String::from(term_name)))
} }
pub fn match_term<'d, 'f>( pub fn match_term<'d, 'f>(
......
...@@ -337,7 +337,7 @@ fn eval_match<'d, 'f: 'd>( ...@@ -337,7 +337,7 @@ fn eval_match<'d, 'f: 'd>(
} else { } else {
eval_match(context, &children[0], &v[0])?; eval_match(context, &children[0], &v[0])?;
let tail = if v.len() > 1 { let tail = if v.len() > 1 {
context.factory.list(v[1..].iter().cloned()) context.factory.list(v.into_iter().skip(1))
} else { } else {
context.factory.nil() context.factory.nil()
}; };
...@@ -376,7 +376,7 @@ fn eval_match<'d, 'f: 'd>( ...@@ -376,7 +376,7 @@ fn eval_match<'d, 'f: 'd>(
use factory::Term::*; use factory::Term::*;
match current.term { match current.term {
Application(current_cons, ref current_children) => { Application(current_cons, ref current_children) => {
let current_cons = &context.factory.string(current_cons.to_owned()); let current_cons = &context.factory.string(::std::string::String::from(current_cons));
eval_match(context, cons, current_cons)?; eval_match(context, cons, current_cons)?;
let current_children = let current_children =
&context.factory.list(current_children.into_iter().cloned()); &context.factory.list(current_children.into_iter().cloned());
......
...@@ -141,6 +141,7 @@ pub fn hashtable_put<'d, 'f: 'd>( ...@@ -141,6 +141,7 @@ pub fn hashtable_put<'d, 'f: 'd>(
.ok_or(()) .ok_or(())
.and_then(TryInto::try_into) .and_then(TryInto::try_into)
.map_err(|_| Error::StrategyFailed)?; .map_err(|_| Error::StrategyFailed)?;
let key = targs[1].clone(); let key = targs[1].clone();
let value = targs[2].clone(); let value = targs[2].clone();
...@@ -282,8 +283,6 @@ pub fn table_keys_fold<'d, 'f: 'd>( ...@@ -282,8 +283,6 @@ pub fn table_keys_fold<'d, 'f: 'd>(
)); ));
} }
let mut current = targs[0].clone();
let table: Rc<RefCell<HashTable<'f>>> = targs[1] let table: Rc<RefCell<HashTable<'f>>> = targs[1]
.get_blob() .get_blob()
.cloned() .cloned()
...@@ -293,6 +292,8 @@ pub fn table_keys_fold<'d, 'f: 'd>( ...@@ -293,6 +292,8 @@ pub fn table_keys_fold<'d, 'f: 'd>(
let table: &RefCell<HashTable<'f>> = table.borrow(); let table: &RefCell<HashTable<'f>> = table.borrow();
let mut current = targs[0].clone();
for key in table.borrow().keys() { for key in table.borrow().keys() {
current = eval_sdef(&sargs[0], context, Vec::new(), vec![key.clone()], current)?; current = eval_sdef(&sargs[0], context, Vec::new(), vec![key.clone()], current)?;
} }
......
...@@ -89,6 +89,7 @@ pub fn indexedSet_put<'d, 'f: 'd>( ...@@ -89,6 +89,7 @@ pub fn indexedSet_put<'d, 'f: 'd>(
.ok_or(()) .ok_or(())
.and_then(TryInto::try_into) .and_then(TryInto::try_into)
.map_err(|_| Error::StrategyFailed)?; .map_err(|_| Error::StrategyFailed)?;
let key = &targs[1]; let key = &targs[1];
let set: &RefCell<IndexedSet> = set.borrow(); let set: &RefCell<IndexedSet> = set.borrow();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment