Skip to content
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

Refactor copy of slices and maps #2128

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Honny1
Copy link
Member

@Honny1 Honny1 commented Oct 9, 2024

This PR refactors:

  • Operations with slices:
    • Removes duplicate copy*Slice functions using a generic copy function or replaces them with the slices.Clone function.
    • Also simplifies the stringSliceWithoutValue function.
    • These changes should not change the behavior.
  • Copying maps:
    • Removes the duplicate copy*Map function using the general function newMapFrom.
    • Reduces the allocation of empty maps using the copyMapPrefferingNil function.
    • This change may affect the behavior so that instead of an empty allocated map, a nil will be returned.

Follows up on: #2122

Removes duplicate copy*Slice functions using a generic copy function
or replaces them with the slices.Clone function.
Also simplifies the stringSliceWithoutValue function.
These changes should not change the behavior.

Signed-off-by: Jan Rodák <[email protected]>
Copy link
Contributor

openshift-ci bot commented Oct 9, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Honny1
Once this PR has been reviewed and has the lgtm label, please assign giuseppe for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Removes the duplicate copy*Map function using the general function newMapFrom.
Reduces the allocation of empty maps using the copyMapPrefferingNil function.
This change may affect the behavior so that instead of an empty allocated map, a nil will be returned.

Signed-off-by: Jan Rodák <[email protected]>
@Honny1 Honny1 marked this pull request as ready for review October 9, 2024 10:10
store.go Outdated
Comment on lines 1792 to 1768
options.BigData = copyContainerBigDataOptionSlice(cOptions.BigData)
options.BigData = slices.Clone(cOptions.BigData)
Copy link
Contributor

Choose a reason for hiding this comment

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

slices.Clone makes a shallow clone, i.e. Data slice is not really copied with this change.

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