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

Add convenience func to reverse callbacks and refactor other methods #7142

Conversation

chatton
Copy link
Contributor

@chatton chatton commented Aug 13, 2024

Description

closes: #7135

This PR adds a reversal function and refactors the callbacks to reduce the amount of index manipulation used through the implementations.


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against the correct branch (see CONTRIBUTING.md).
  • Linked to GitHub issue with discussion and accepted design, OR link to spec that describes this work.
  • Code follows the module structure standards and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/).
  • Added relevant godoc comments.
  • Provide a conventional commit message to follow the repository standards.
  • Include a descriptive changelog entry when appropriate. This may be left to the discretion of the PR reviewers. (e.g. chores should be omitted from changelog)
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Review SonarCloud Report in the comment section below once CI passes.

Comment on lines +456 to +457
negotiatedVersions = slices.Clone(negotiatedVersions)
slices.Reverse(negotiatedVersions)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the one thing I don't like about this PR, the negotiatedVersions are provided in reverse order.

I think we can either do this, require the caller to provide the calling fn to reverse them (easy to forget), or just reverse directly without copying, which will likely not be a problem but this version is just being extra careful.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah. Not beautiful, but its all part of this legacy module construction so I'm fine with it

@chatton chatton added priority PRs that need prompt reviews feat: port-router labels Aug 13, 2024
@chatton chatton added this to the 05-port refactor alpha milestone Aug 13, 2024
@chatton chatton mentioned this pull request Aug 13, 2024
10 tasks
Copy link

sonarcloud bot commented Aug 13, 2024

negotiatedVersions := make([]string, len(im.cbs))

for i := len(im.cbs) - 1; i >= 0; i-- {
var negotiatedVersions []string
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] we could be slightly more efficient by doing:

negotiatedVersions := make([]string,0, len(im.cbs)) which would pre-allocate the needed capacity (but not the length).

If we know there's a 1:1 relationship between im.cbs and negotiatedVersions (so that the length is exactly the same) we could even do

negotiatedVersions := make([]string,len(im.cbs)

for i, cb := range im.reverseCallbacks() {
     ...
     negotiatedversions[i] =

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah no harm!

// reverseCallbacks returns a copy of the callbacks in reverse order.
// the majority of handlers are called in reverse order, so this can be used
// in those cases to prevent needing to iterate backwards over the callbacks.
func (im *LegacyIBCModule) reverseCallbacks() []ClassicIBCModule {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] since this doesn't actually reverse the callbacks, but returns the "reversed", what about calling it reversedCallbacks?

Copy link
Member

Choose a reason for hiding this comment

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

sgtm, I can't think of any better naming tbh

Copy link
Member

@damiannolan damiannolan left a comment

Choose a reason for hiding this comment

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

lgtm!

Comment on lines +456 to +457
negotiatedVersions = slices.Clone(negotiatedVersions)
slices.Reverse(negotiatedVersions)
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeah. Not beautiful, but its all part of this legacy module construction so I'm fine with it

// reverseCallbacks returns a copy of the callbacks in reverse order.
// the majority of handlers are called in reverse order, so this can be used
// in those cases to prevent needing to iterate backwards over the callbacks.
func (im *LegacyIBCModule) reverseCallbacks() []ClassicIBCModule {
Copy link
Member

Choose a reason for hiding this comment

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

sgtm, I can't think of any better naming tbh

@chatton chatton merged commit f5ab15b into feat/port-router Aug 13, 2024
15 of 17 checks passed
@chatton chatton deleted the cian/issue#7135-add-convenience-func-to-reverse-callbacks-and-refactor-other-methods branch August 13, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: port-router priority PRs that need prompt reviews
Projects
Status: Done 🥳
Development

Successfully merging this pull request may close these issues.

3 participants