Skip to content

⚡️ Remove useless clone #486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 4, 2025
Merged

Conversation

lrazovic
Copy link
Member

@lrazovic lrazovic commented May 9, 2025

This pull request introduces several updates across multiple files to improve code consistency, enhance performance, and adopt best practices. Key changes include enforcing stricter linting rules, replacing redundant .clone() calls with direct references, adding const constructors for better compile-time optimizations, and removing unnecessary imports. These changes aim to streamline the codebase and improve maintainability.

Linting and Code Quality Improvements:

  • Updated Cargo.toml to enforce stricter linting by changing redundant_clone from "warn" to "deny" and adding a new lint rule missing-const-for-fn set to "warn".

Performance Optimizations:

  • Replaced .clone() calls with direct references or moved values where cloning was unnecessary, e.g., in pallets/funding/src/functions/1_application.rs, pallets/funding/src/functions/3_auction.rs, and pallets/funding/src/instantiator/chain_interactions.rs. [1] [2] [3]

Compile-Time Improvements:

  • Added const constructors for several structs and utility functions across the codebase, such as CheckNonce, EvaluationParams, and UserToFundingAsset, enabling compile-time evaluation where possible. [1] [2] [3]

Simplification of Code:

  • Removed unnecessary .clone() calls in functional operations, such as group_by and map, to simplify logic and reduce redundancy in pallets/funding/src/instantiator/calculations.rs. [1] [2]
  • Replaced wildcard imports with explicit imports for better clarity and to avoid potential namespace conflicts.

Miscellaneous Enhancements:

  • Converted several methods in pallets/funding/src/types.rs to const functions, such as usd_ticket_above_minimum_per_participation and multiplier, to improve performance and enable compile-time checks. [1] [2]

@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from a514ee5 to 1e5802c Compare May 12, 2025 08:47
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from a4df891 to 4390d0e Compare May 12, 2025 08:47
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from 1e5802c to a4afbb3 Compare May 12, 2025 08:49
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from 4390d0e to eeada01 Compare May 12, 2025 08:49
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from a4afbb3 to f6c04d2 Compare May 12, 2025 08:58
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from eeada01 to e7ffa1b Compare May 12, 2025 11:36
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from f6c04d2 to 7e9c5ce Compare May 12, 2025 11:36
@lrazovic lrazovic changed the title chore: remove useless clone ⚡️ Remove useless clone May 16, 2025
@lrazovic lrazovic requested a review from Copilot May 16, 2025 14:42
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes unnecessary .clone() calls and marks simple constructors and accessors as const fn to enforce immutability at compile time, while tightening the redundant_clone lint.

  • Removed redundant clone() calls across runtime and pallet code.
  • Added const fn qualifiers to simple constructors and methods.
  • Updated Cargo.toml to deny redundant clones and warn on missing const fn.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.

Show a summary per file
File Description
runtimes/polimec/src/xcm_config.rs Removed useless clone and switched to is_some_and
polimec-common/common/src/lib.rs Made from(Vec<>) constructor a const fn
pallets/proxy-bonding/src/functions.rs Removed redundant .clone() on treasury and account parameters
pallets/on-slash-vesting/src/lib.rs Changed on_slash to take &Balance and updated usages
pallets/linear-release/src/lib.rs Converted max_vesting_schedules to const fn
pallets/funding/src/types.rs Added const fn to multiple constructors and predicate methods
pallets/funding/src/instantiator/types.rs Marked all .new methods as const fn
pallets/funding/src/instantiator/mod.rs Removed clippy allow for wildcard imports
pallets/funding/src/instantiator/chain_interactions.rs Removed redundant clones, made new a const fn
pallets/funding/src/instantiator/calculations.rs Dropped unnecessary clone before grouping bids
pallets/funding/src/functions/misc.rs Removed .clone() on polimec_account
pallets/funding/src/functions/5_settlement.rs Removed clones on escrow_account and slashed_amount
pallets/funding/src/functions/3_auction.rs Dropped .clone() on bidder in event emission
pallets/funding/src/functions/1_application.rs Removed clones on issuer and did in project creation
pallets/dispenser/src/extensions.rs Made constructor from(nonce) a const fn
Cargo.toml Set redundant_clone = "deny" and added missing-const-for-fn
Comments suppressed due to low confidence (2)

pallets/funding/src/instantiator/mod.rs:15

  • The wildcard imports here are no longer exempted by clippy, which may trigger lint errors. Consider replacing * imports with specific items or re-adding a lint allowance for wildcard imports.
use crate::{traits::*, *};

pallets/funding/src/instantiator/chain_interactions.rs:15

  • This const fn invokes RefCell::new(0u64), which is not a const fn in the standard library. It will fail to compile. Either revert to a non-const function or ensure all called functions are const-compatible.
pub const fn new(ext: OptionalExternalities) -> Self {

@lrazovic lrazovic self-assigned this May 16, 2025
@lrazovic lrazovic requested a review from dastansam May 16, 2025 14:45
@lrazovic lrazovic marked this pull request as ready for review May 16, 2025 14:45
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from e7ffa1b to b5652c4 Compare May 19, 2025 06:15
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch 2 times, most recently from 8b86a93 to b244067 Compare May 19, 2025 06:48
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from b5652c4 to 2db9c76 Compare May 19, 2025 06:48
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from b244067 to e9c508f Compare May 20, 2025 06:21
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from 2db9c76 to c9be272 Compare May 20, 2025 06:21
@dastansam dastansam force-pushed the 05-09-chore_remove_useless_clone branch from e9c508f to 1e2f49d Compare May 23, 2025 11:43
@dastansam dastansam mentioned this pull request May 23, 2025
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from 156f866 to e22ac65 Compare May 28, 2025 13:35
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch 2 times, most recently from 093bd7c to bda4556 Compare May 28, 2025 13:38
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from e22ac65 to 378a176 Compare May 28, 2025 13:38
@dastansam dastansam force-pushed the 05-09-chore_remove_useless_clone branch from bda4556 to 18ad867 Compare July 9, 2025 06:38
@dastansam dastansam force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from 378a176 to 48db973 Compare July 9, 2025 06:38
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from 18ad867 to f6c2185 Compare July 25, 2025 14:19
@lrazovic lrazovic force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from 48db973 to d4e10e0 Compare July 25, 2025 14:19
@dastansam dastansam force-pushed the 05-09-feat_simplify_the_acceptable_assets branch from d4e10e0 to 48db973 Compare July 25, 2025 21:21
@dastansam dastansam force-pushed the 05-09-chore_remove_useless_clone branch from f6c2185 to 18ad867 Compare July 25, 2025 21:21
Copy link
Member Author

lrazovic commented Aug 4, 2025

Merge activity

  • Aug 4, 7:49 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Aug 4, 7:57 AM UTC: Graphite rebased this pull request as part of a merge.
  • Aug 4, 7:58 AM UTC: @lrazovic merged this pull request with Graphite.

@lrazovic lrazovic changed the base branch from 05-09-feat_simplify_the_acceptable_assets to graphite-base/486 August 4, 2025 07:53
@lrazovic lrazovic changed the base branch from graphite-base/486 to main August 4, 2025 07:55
@lrazovic lrazovic force-pushed the 05-09-chore_remove_useless_clone branch from 18ad867 to 76d75a9 Compare August 4, 2025 07:56
@lrazovic lrazovic merged commit 25a8367 into main Aug 4, 2025
1 check passed
@lrazovic lrazovic deleted the 05-09-chore_remove_useless_clone branch August 4, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants