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

x/tools/internal/refactor/inline: optimize binding decls in if statements (etc) #63253

Open
adonovan opened this issue Sep 26, 2023 · 0 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

Currently, inlining this call:

if strings.HasPrefix(path, "/") {

gives:

		if func(prefix string) bool {
			return len(path) >= len(prefix) && path[0:len(prefix)] == prefix
		}("/") {

primarily because the prefix needs a variable but the context--an if condition--doesn't allow statements. Ideally it would put the binding decl in the if condition like so:

		if prefix := "/"; len(path) >= len(prefix) && path[0:len(prefix)] == prefix {

or introduce the decl at a higher level:

		var prefix = "/"
		if len(path) >= len(prefix) && path[0:len(prefix)] == prefix {
@gopherbot gopherbot added the Tools This label describes issues relating to any tools in the x/tools repository. label Sep 26, 2023
@gopherbot gopherbot added this to the Unreleased milestone Sep 26, 2023
@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 27, 2023
@adonovan adonovan changed the title x/tools/interna/refactor/inline: optimize binding decls in if statements (etc) x/tools/internal/refactor/inline: optimize binding decls in if statements (etc) Oct 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants