menu

prefer-clone-from

Prefer Clone.cloneFrom when replacing a cloneable value

Assigning a newly cloned value discards storage that the destination may be able to reuse. Instead, you SHOULD call cloneFrom so the destination can reuse its existing allocation.

Reported

1import { rc } from "destack:memory";2 3function replace(target: &exclusive rc.Rc<int32>, source: &readonly rc.Rc<int32>): void {4    *target = source.clone();5}

Accepted

1import { rc } from "destack:memory";2 3function replace(target: &exclusive rc.Rc<int32>, source: &readonly rc.Rc<int32>): void {4    target.cloneFrom(source);5}