github.com/zhiqiangxu/util@v0.0.0-20230112053021-0a7aee056cd5/bytes/realloc.go (about)

     1  package bytes
     2  
     3  // Realloc is like realloc of c.
     4  func Realloc(b []byte, n int) []byte {
     5  	newSize := len(b) + n
     6  	if cap(b) < newSize {
     7  		bs := make([]byte, len(b), newSize)
     8  		copy(bs, b)
     9  		return bs
    10  	}
    11  
    12  	// slice b has capability to store n bytes
    13  	return b
    14  }