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

If-Statements Optimization #468

Closed
JessonChan opened this issue Jul 16, 2020 · 2 comments · Fixed by #532
Closed

If-Statements Optimization #468

JessonChan opened this issue Jul 16, 2020 · 2 comments · Fixed by #532

Comments

@JessonChan
Copy link
Member

func foo() bool {
	println("foo")
	return true
}
func bar() bool {
	println("bar")
	return true
}

func fake() bool {
	println("fake")
	return false
}

if foo() || bar() {
}
println("---")
if foo() && bar() {
}
println("---")
if fake() && bar() {
}

result:

foo
bar
---
foo
bar
---
fake
bar

expect

foo
---
foo
bar
---
fake
@xushiwei
Copy link
Member

Not only in if statement. For example:

x := foo() || bar()

@wangkuiyi
Copy link
Contributor

Should we label this issue a bug fix other than an enhancement?

visualfc added a commit to visualfc/gop that referenced this issue Aug 7, 2020
visualfc added a commit to visualfc/gop that referenced this issue Aug 11, 2020
xushiwei pushed a commit that referenced this issue Aug 14, 2020
* cl: fix #468 binary expr LAnd LOr to funcLit

* cl: expr makeOpFuncLit add pos

* cl: TestOpLAndLOr2

* cl: compileBinaryExpr opLOr/opLAnd type check

* cl: compileBinaryExpr optimization LAnd/LOr if v.X is constVal

* cl: fix #468 binary expr LAnd LOr to funcLit

* cl: expr makeOpFuncLit add pos

* cl: TestOpLAndLOr2

* cl: compileBinaryExpr opLOr/opLAnd type check

* cl: compileBinaryExpr optimization LAnd/LOr if v.X is constVal

* exec: JumpCond => JumpFlag, add JcNotPopMask

* cl: compileBinaryExpr  opLAnd opLOr use JumpIf

* bytecode: opJmpIf

* bytecode: add TestLAnd/TestLOr

* cl: clean code

* golang: fix JmpIf

* golang: hard code jc.NotPop

* golang: add testdata/land_lor

* cl: compileBinaryExpr simple
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.

3 participants