tinygo-org / tinygo

Go compiler for small places. Microcontrollers, WebAssembly (WASM/WASI), and command-line tools. Based on LLVM.
https://tinygo.org
Other
15.48k stars 913 forks source link

WIP: implement realloc() for slice growth #4363

Closed dgryski closed 3 months ago

dgryski commented 3 months ago

Hmm. Good point. I was looking at this for an optimization where the caller is doing a lot of appends. I'll check the spec and see if we have any wiggle room.

dgryski commented 3 months ago
If the capacity of s is not large enough to fit the additional values, append [allocates](https://go.dev/ref/spec#Allocation) a new, sufficiently large underlying array that fits both the existing slice elements and the additional values. Otherwise, append re-uses the underlying array.

I think the word "new" there certainly implies we can't realloc(), and the the three-form slice notation was added to allow people to append to a slice and know that it would be a copy that was returned. Oh well, back to the drawing board...