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

wormhole: Don't call reflect twice on message #94

Closed
wants to merge 1 commit into from

Conversation

Jacalz
Copy link
Contributor

@Jacalz Jacalz commented Apr 17, 2023

Cleans up some code that was doing double reflect calls when only one was necessary,

@psanford
Copy link
Owner

The go specification does not require an interface implementation to be a pointer type, as long as the method receiver is not a pointer:

package main

import (
	"fmt"
)

type concreteFoo struct {
}

func (c concreteFoo) String() string {
	return "concreteFoo"
}

type stringer interface {
	String() string
}

func takesAStringer(s stringer) {
	fmt.Println(s.String())
}

func main() {
	f := concreteFoo{}
	takesAStringer(f)
}

@Jacalz
Copy link
Contributor Author

Jacalz commented Apr 17, 2023

But the methods for the collectable types used within the project are all pointer receivers.
image
I don't see any reason for keeping the runtime check around for something that only can occur as a bug on the developer side and is checked by the compiler in our case as all types use pointer receivers (like is most usual in Go code over all).

@psanford
Copy link
Owner

I would take this change If you wrote a static analysis test that showed that every implementation of this interface used pointer types.

@Jacalz Jacalz changed the title wormhole: Don't check collectable struct pointer wormhole: Don't call reflect twice on message Apr 17, 2023
@Jacalz
Copy link
Contributor Author

Jacalz commented Apr 17, 2023

I've pushed a commit to at least not get the value twice from msg using reflect. It should be better than nothing in the meantime.

@Jacalz
Copy link
Contributor Author

Jacalz commented Apr 17, 2023

I might actually have a better fix for this. Will see what I can do.

@Jacalz
Copy link
Contributor Author

Jacalz commented Apr 17, 2023

I have opened #95 with a different approach that checks the struct pointer in a different way without using the reflect package at all. If that PR is rejected, this is still a nice improvement over the previous code.

@psanford
Copy link
Owner

Can you squash this into a single commit?

@Jacalz
Copy link
Contributor Author

Jacalz commented Aug 17, 2023

Done

@Jacalz
Copy link
Contributor Author

Jacalz commented Oct 20, 2023

Ping @psanford

@psanford psanford closed this in 68dc344 Oct 24, 2023
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