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

for range start:end:step optimization #875

Closed
xushiwei opened this issue Nov 10, 2021 · 0 comments · Fixed by #1003
Closed

for range start:end:step optimization #875

xushiwei opened this issue Nov 10, 2021 · 0 comments · Fixed by #1003
Assignees
Milestone

Comments

@xushiwei
Copy link
Member

xushiwei commented Nov 10, 2021

Proposal

#865: for range start:end:step

	for range :10 {
		fmt.Println("Hi")
	}

Now it generates the following code:

	for _gop_it := builtin.NewRange__0(0, 10, 1).Gop_Enum(); ; {
		var _gop_ok bool
		_, _gop_ok = _gop_it.Next()
		if !_gop_ok {
			break
		}
		fmt.Println("Hi")
	}

It can be optimized to:

for i := 0; i < 10; i++ {
	fmt.Println("Hi")
}

Background

None

Workarounds

None

@xushiwei xushiwei changed the title for range start:end:step optimization for range start:end:step optimization Nov 10, 2021
@xushiwei xushiwei added this to the Go+ v1.1 milestone Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants