When append
a slice, the slice may be enlarged if necessary. Because the spec doesn't specify the algorithm, I am curious about it.
I try to find the append
implementation in the Go source code, but can't find it.
Could anyone explain the specified algorithm for enlarging slice? Is the capacity always doubled? or Could anyone provide the source code position of append
? I can check it myself.
The code responsible for growing slices in append
can be found here.
So in the current implementation, the rules are:
Presumably this isn't part of the specification so the heuristics can be changed in future if needed.