Commit 3c55ee64 authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

cmd/compile: refactor out method-called-as-function check

Change-Id: I417aae8622d7d363863704594680bd2502a09049
Reviewed-on: https://go-review.googlesource.com/27463
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 376d9665
......@@ -179,7 +179,7 @@ func ishairy(n *Node, budget *int32) bool {
break
}
if n.Left.Op == ONAME && n.Left.Left != nil && n.Left.Left.Op == OTYPE && n.Left.Right != nil && n.Left.Right.Op == ONAME { // methods called as functions
if n.isMethodCalledAsFunction() {
if d := n.Left.Sym.Def; d != nil && d.Func.Inl.Len() != 0 {
*budget -= d.Func.InlCost
break
......@@ -458,10 +458,8 @@ func inlnode(n *Node) *Node {
}
if n.Left.Func != nil && n.Left.Func.Inl.Len() != 0 && !isIntrinsicCall1(n) { // normal case
n = mkinlcall(n, n.Left, n.Isddd)
} else if n.Left.Op == ONAME && n.Left.Left != nil && n.Left.Left.Op == OTYPE && n.Left.Right != nil && n.Left.Right.Op == ONAME { // methods called as functions
if n.Left.Sym.Def != nil {
n = mkinlcall(n, n.Left.Sym.Def, n.Isddd)
}
} else if n.isMethodCalledAsFunction() && n.Left.Sym.Def != nil {
n = mkinlcall(n, n.Left.Sym.Def, n.Isddd)
}
case OCALLMETH:
......@@ -1004,3 +1002,7 @@ func setlno(n *Node, lno int32) {
setlnolist(n.Ninit, lno)
setlnolist(n.Nbody, lno)
}
func (n *Node) isMethodCalledAsFunction() bool {
return n.Left.Op == ONAME && n.Left.Left != nil && n.Left.Left.Op == OTYPE && n.Left.Right != nil && n.Left.Right.Op == ONAME
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment