英文:
Does the Go compiler concatenate strings separated by a plus sign?
问题
让我们假设我在代码中有以下内容:
err := "这是一个非常长的错误消息" +
"它跨越多行。"
Go语言会在底层将其编译为一个字符串,或者在这里进行相加操作会有一些小的性能损耗吗?
英文:
Let's say I have the following in my code:
err := "This is a very long error message"+
"that spans multiple lines."
Will Go compile this under the hood into one string, or is there some small penalty associated with doing the addition there?
答案1
得分: 8
这是一个常量表达式,并且规定在编译时进行评估。
英文:
It's a constant expression and is specified to be evaluated at compile time.
答案2
得分: 2
这是针对Go 1.3编译的一个字符串。
go.string."这是一个跨越多行的非常长的错误消息。"
对于早期版本,可能也是一个字符串。
英文:
It's compiled as one string for Go 1.3.
go.string."This is a very long error messagethat spans multiple lines."
It's probably one string for earlier versions too.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论