jafioti / luminal

Deep learning at the speed of light.

Home Page:https://luminalai.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimize clone

npuichigo opened this issue · comments

I'm wondering why there're many clones although we already have moved self and other parameters.

for term in self.terms.clone().into_iter() {
match term {
Term::Var(c) if c == var => {
for t in expr.terms.clone().into_iter() {

Please help me to check if I'm right?

You are right there can be far less. It has to do with the ExpressionStorage trait, which only implements IntoIterator which consumes the object. Instead we should implement IntoIterator on &S so that it yields &Term such that cloning isn't needed

Yes. But since we are already consuming the object here, maybe just removing the clone and let into_iter consume self is enough?

I think it is used more than once there

At least removing clone in L258 compiles and passes the unit test.

I removed most of the clones by adding an .iter_ref() function to expressionstorage, which creates a borrowed iterator.

I'll go ahead and close this, there's not many clones left in symbolic.