Skip to content

Avoid manually-coded loops#2087

Merged
openshift-merge-bot[bot] merged 5 commits intocontainers:mainfrom
mtrmac:shorten
Sep 5, 2024
Merged

Avoid manually-coded loops#2087
openshift-merge-bot[bot] merged 5 commits intocontainers:mainfrom
mtrmac:shorten

Conversation

@mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Sep 4, 2024

Use slices and maps, or other existing features, where appropriate.

This is basically a single pass looking for append.*..., and skimming all for loops.

Copy link
Contributor

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Looks great to me overall

}
options.BigData = append(options.BigData, copyImageBigDataOptionSlice(iOptions.BigData)...)
options.NamesHistory = append(options.NamesHistory, copyStringSlice(iOptions.NamesHistory)...)
options.NamesHistory = append(options.NamesHistory, iOptions.NamesHistory...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I only skimmed/spot checked but I noticed in this one we stopped copying...expected?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes — append is “grow slice + copy incoming data to the destination”; so making another copy of the incoming data could only make a difference if the source and destination were overlapping. That’s not the case here (the destination is either unset, or already a freshly-allocated clone).

Actually I’ll remove another copy when updating options.Digests field above.

The BigData one is different - copyImageBigDataOptionSlice is a deep copy, but append only does a shallow one.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 4, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cgwalters, mtrmac

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

The pull request process is described here

Details 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

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Conservatively use Index* + Delete to delete the
first element where it's not obvious that the code would really
want to delete all instances.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Use the "slices", "maps" standard library packages, or other
readily-available features.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
@rhatdan
Copy link
Member

rhatdan commented Sep 5, 2024

/lgtm

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.

3 participants