go拼接字符串的方式以及性能比较

douyacun · · 803 次点击
douyacun
持续踌躇满志,间歇性做吃等死
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 &amp;buf[off], write at &amp;buf[len(buf)] lastRead readOp // last read operation, so that Unread* can work correctly. } ``` 都是存储字节slice的, - Builder writeString是append到buf中,会有扩容操作, - Buffer writeString 是通过copy内存实现的 Buffer用起来更顺手
#2
更多评论
亲, 你把strings.Builder放哪了.
#1
亲,copy内存就不需要扩容了么... 这些字符串操作本质上其实都是copy内存. 为啥Buffer用起来更顺手呢?
#3