github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/pipes/term/utils.go (about)

     1  package term
     2  
     3  // Shamelessly stolen from https://blog.golang.org/go-slices-usage-and-internals
     4  // (it works well so why reinvent the wheel?)
     5  func appendBytes(slice []byte, data ...byte) []byte {
     6  	m := len(slice)
     7  	n := m + len(data)
     8  	if n > cap(slice) { // if necessary, reallocate
     9  		// allocate double what's needed, for future growth.
    10  		newSlice := make([]byte, (n+1)*2)
    11  		copy(newSlice, slice)
    12  		slice = newSlice
    13  	}
    14  	slice = slice[0:n]
    15  	copy(slice[m:n], data)
    16  	return slice
    17  }