Go函数中定义的常量与包顶部定义的常量之间是否存在差异?

gil*_*lef 2 constants go

在函数范围内部和外部定义的常量之间是否存在差异(主要是性能)?

func (this *Person) SetDefaults() *Person{
    const (
        defaultFirstName = "first"
        defaultLastName  = "last"
    )

    //do stuff with constants
    return this
}
Run Code Online (Sandbox Code Playgroud)

const (
    defaultFirstName = "first"
    defaultLastName  = "last"
)
func (this *Person) SetDefaults() *Person{
    //do stuff with constants
    return this
}  
Run Code Online (Sandbox Code Playgroud)

Dav*_*rth 5

唯一的区别是范围界定

在编译期间,只需在每个引用处交换常量.
因此,在运行时它的来源没有区别.