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

Merged
merged 2 commits into from
Oct 25, 2024

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

@Honny1 Honny1 force-pushed the refactor-copy-map branch 2 times, most recently from a9ef2aa to 13a96fe Compare October 9, 2024 10:05
@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.

Copy link
Member Author

Choose a reason for hiding this comment

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

The previous copyContainerBigDataOptionSlice function used the slices.Clone function to copy data. So I would expect similar behavior.

Copy link
Member

Choose a reason for hiding this comment

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

It used slices.Clone() to copy the Data field in each element in the slice. The godoc for slices.Clone() notes that it only copies using assignment, so a new slice would not be created for Data fields.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I've reverted these changes.

@rhatdan
Copy link
Member

rhatdan commented Oct 18, 2024

/approved
LGTM

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]>
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]>
@rhatdan
Copy link
Member

rhatdan commented Oct 25, 2024

/approve
@kolyshkin @nalind @mtrmac @Luap99 @flouthoc @giuseppe PTAL

Copy link
Contributor

openshift-ci bot commented Oct 25, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Honny1, rhatdan

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

The pull request process is described 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

@nalind
Copy link
Member

nalind commented Oct 25, 2024

LGTM

@rhatdan
Copy link
Member

rhatdan commented Oct 25, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm label Oct 25, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit e636ada into containers:main Oct 25, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants