Search Options

Results per page
Sort
Preferred Languages
Advance

Results 1 - 2 of 2 for copyCheck (0.09 sec)

  1. src/strings/builder.go

    func (b *Builder) Grow(n int) {
    	b.copyCheck()
    	if n < 0 {
    		panic("strings.Builder.Grow: negative count")
    	}
    	if cap(b.buf)-len(b.buf) < n {
    		b.grow(n)
    	}
    }
    
    // Write appends the contents of p to b's buffer.
    // Write always returns len(p), nil.
    func (b *Builder) Write(p []byte) (int, error) {
    	b.copyCheck()
    	b.buf = append(b.buf, p...)
    	return len(p), nil
    }
    
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Wed Apr 17 21:09:59 UTC 2024
    - 3.2K bytes
    - Viewed (0)
  2. src/strings/builder_test.go

    		t.Error(err)
    	}
    	if err := b.WriteByte(0); err != nil {
    		t.Error(err)
    	}
    	check(t, &b, "a\x00")
    }
    
    func TestBuilderAllocs(t *testing.T) {
    	// Issue 23382; verify that copyCheck doesn't force the
    	// Builder to escape and be heap allocated.
    	n := testing.AllocsPerRun(10000, func() {
    		var b Builder
    		b.Grow(5)
    		b.WriteString("abcde")
    		_ = b.String()
    	})
    	if n != 1 {
    Registered: Wed Jun 12 16:32:35 UTC 2024
    - Last Modified: Mon Feb 19 19:51:15 UTC 2024
    - 8.1K bytes
    - Viewed (0)
Back to top