- `+` 拼接 最慢 少量比较推荐
- `strings.join` 拼接 其次-推荐
- `buffers.NewBufferString` 拼接 最快,需要自己实现
博客原文链接:[https://www.douyacun.com/article/64bf57a2d3099acbb960ca561d225628](https://www.douyacun.com/article/64bf57a2d3099acbb960ca561d225628)
1楼 <a href="/user/focusonline" title="@focusonline">@focusonline</a>
```go
type Builder struct {
addr *Builder // of receiver, to detect copies by value
buf []byte
}
```
```go
type Buffer struct {
buf []byte // contents are the bytes buf[off : len(buf)]
off int // read at &buf[off], write at &buf[len(buf)]
lastRead readOp // last read operation, so that Unread* can work correctly.
}
```
都是存储字节slice的,
- Builder writeString是append到buf中,会有扩容操作,
- Buffer writeString 是通过copy内存实现的
Buffer用起来更顺手
#2
更多评论