Skip to content

refactor: optimize variable containment check and remove redundant clones#213

Open
moostoopha wants to merge 1 commit into
wcm-io-devops:mainfrom
moostoopha:refactor/optimize-variable-containment-check
Open

refactor: optimize variable containment check and remove redundant clones#213
moostoopha wants to merge 1 commit into
wcm-io-devops:mainfrom
moostoopha:refactor/optimize-variable-containment-check

Conversation

@moostoopha

Copy link
Copy Markdown

spotted a couple of small things while reviewing the deploy step pipeline variables change

  • tmp_loop_var.clone().value.unwrap() clones the whole struct just to read one field, changed to tmp_loop_var.value.clone().unwrap()
  • vars_yaml.clone().contains(&vc) inside the cloud var loop is O(n²), replaced with a HashSet built once before the loop for O(1) lookup
  • removed a copy-paste docstring on PipelineVariable that was referencing EnvironmentVariable

all 24 tests pass

…ones

Replace O(n²) vec scan with a HashSet for cloud-vs-yaml variable diffing
in both set_env_vars_from_file and set_pipeline_vars_from_file. Also fix
tmp_loop_var.clone().value to tmp_loop_var.value.clone() to avoid cloning
the whole struct just to access one field. Remove duplicate/wrong docstring
on PipelineVariable (copy-paste from EnvironmentVariable).

Copilot AI left a comment

Copy link
Copy Markdown

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 refactors variable processing to reduce unnecessary cloning and improve the performance of “cloud vs YAML” containment checks when determining which variables should be deleted.

Changes:

  • Avoids cloning entire variable structs when only the value field is needed for decryption checks.
  • Replaces repeated Vec::contains scans inside the cloud-variable loop with a precomputed HashSet for faster lookups.
  • Removes a redundant/copy-pasted doc comment on PipelineVariable.

Reviewed changes

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

File Description
src/variables.rs Reduces cloning in secret handling and replaces repeated Vec::contains checks with a prebuilt HashSet for faster membership tests.
src/models/variables.rs Removes an incorrect/redundant doc comment on PipelineVariable.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tobias-richter

Copy link
Copy Markdown
Contributor

@lokeshnasina can you please review and test? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants