我对参数类型内部构造函数中的类型注释有点困惑。
以下 4 种方法在 JIT 推理效率和运行时效率方面有什么区别吗?
immutable MyType{T}
x::T
MyType{T}(x::T) = new{T}(x + x)
end
immutable MyType{T}
x::T
MyType(x::T) = new{T}(x + x)
end
immutable MyType{T}
x::T
MyType(x::T) = new(x + x)
end
immutable MyType{T}
x::T
MyType{T}(x::T) = new(x + x)
end
他们都为x = MyType{Int}(1)
我宣布MyType
使用以上4种方法:
immutable MyType1{T}
x::T
MyType1{T}(x::T) = new{T}(x + x)
end
immutable MyType2{T}
x::T
MyType2(x::T) = new{T}(x + x)
end
immutable MyType3{T}
x::T
MyType3{T}(x::T) = new(x + x)
end
immutable MyType4{T}
x::T
MyType4(x::T) = new(x + x)
end
然后打印他们的 LLVM 字节码:code_llvm(MyType1{Int},Int)
并比较了输出,它们完全相同,所以我认为4种方法没有区别。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)