title: Why does golang strings.Builder implements String() like this?
body: <p>The implementation is</p>
  
  <pre><code>// String returns the accumulated string.
  func (b *Builder) String() string {
      return *(*string)(unsafe.Pointer(&amp;b.buf))
  }
  </code></pre>
  
  <p>According to my test, converting []byte to string uses "copy on write", or the compiler generates the deep copy instructions if either one is changing the insided slice:</p>
  
  <pre><code>{
          a := []byte{'a'}
          s1 := string(a)
          a[0] = 'b'
          fmt.Println(s1) // a
      }
  
      {
          a := "a"
          b := []byte(a)
          b[0] = 'b'
          fmt.Println(a) // a
      }
  </code></pre>
  
  <p>So what happens if it's implemented as below?</p>
  
  <pre><code>// String returns the accumulated string.
  func (b *Builder) String() string {
      return string(b.buf)
  }
  </code></pre>