Created
April 11, 2025 07:19
-
-
Save ncruces/e7974aa3d155c2374c52c040fe613b3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/golang/go/blob/go1.24.0/src/bytes/bytes.go#L664-L673 | |
func fill[T comparable](buf []T, value T) { | |
var zero T | |
switch { | |
case value == zero: | |
clear(buf) | |
case len(buf) != 0: | |
buf[0] = value | |
maxChunk := 8 * 1024 / unsafe.Sizeof(value) | |
for i := 1; i < len(buf); { | |
chunk := min(i, int(maxChunk)) | |
i += copy(buf[i:], buf[:chunk]) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment