compiler: inline expressions with type conversions, fix #1879
Don't count `string(data)` or `[]byte(data)` as function calls.
This commit is contained in:
parent
6b3afe9131
commit
1d6d7206e9
4 changed files with 48 additions and 9 deletions
|
@ -869,12 +869,7 @@ func (c *codegen) Visit(node ast.Node) ast.Visitor {
|
|||
|
||||
switch fun := n.Fun.(type) {
|
||||
case *ast.Ident:
|
||||
var pkgName string
|
||||
if len(c.pkgInfoInline) != 0 {
|
||||
pkgName = c.pkgInfoInline[len(c.pkgInfoInline)-1].Pkg.Path()
|
||||
}
|
||||
f, ok = c.funcs[c.getIdentName(pkgName, fun.Name)]
|
||||
|
||||
f, ok = c.getFuncFromIdent(fun)
|
||||
isBuiltin = isGoBuiltin(fun.Name)
|
||||
if !ok && !isBuiltin {
|
||||
name = fun.Name
|
||||
|
@ -1956,6 +1951,16 @@ func (c *codegen) newFunc(decl *ast.FuncDecl) *funcScope {
|
|||
return f
|
||||
}
|
||||
|
||||
func (c *codegen) getFuncFromIdent(fun *ast.Ident) (*funcScope, bool) {
|
||||
var pkgName string
|
||||
if len(c.pkgInfoInline) != 0 {
|
||||
pkgName = c.pkgInfoInline[len(c.pkgInfoInline)-1].Pkg.Path()
|
||||
}
|
||||
|
||||
f, ok := c.funcs[c.getIdentName(pkgName, fun.Name)]
|
||||
return f, ok
|
||||
}
|
||||
|
||||
// getFuncNameFromSelector returns fully-qualified function name from the selector expression.
|
||||
// Second return value is true iff this was a method call, not foreign package call.
|
||||
func (c *codegen) getFuncNameFromSelector(e *ast.SelectorExpr) (string, bool) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue