shramee / starklings-cairo1

An interactive tutorial to get you up and running with Cairo v1 and Starknet
MIT License
450 stars 394 forks source link

Unnecessary `clone()` usage in move_semantics1.cairo file #179

Closed TAdev0 closed 10 months ago

TAdev0 commented 10 months ago

Current move_semantics1 exercice implements main as follows :

fn main() {
    let arr0 = ArrayTrait::new();

    let arr1 = fill_arr(arr0);

    // This is just a print statement for arrays.
    arr1.clone().print();

    //TODO fix the error here without modifying this line.
    arr1.append(88);

    arr1.clone().print();
}

Nevertheless, using clone() in the last line is not necessary, as ownership of arr1 can be given to print method without issue because it is never used after that. It would avoid unnecessary clone call to replace main with :

fn main() {
    let arr0 = ArrayTrait::new();

    let arr1 = fill_arr(arr0);

    // This is just a print statement for arrays.
    arr1.clone().print();

    //TODO fix the error here without modifying this line.
    arr1.append(88);

    arr1.print();
}
TAdev0 commented 10 months ago

@shramee do you want me to push a PR to remove the unnecessary clone() call, or not necessary?

shramee commented 10 months ago

@TAdev0 Yes please ser :)