ruby / tmm1.net wrote:
> This is the best I could come up with. Definitely not ideal since it
> allocates another ruby object.

What about using rb_str_resize?

rb_str_resize may work even better if we remove the 1024 byte threshold
and trust the realloc implementation to do the right thing.

Additionally, rb_str_freeze may also be smarter and force a resize
unconditionally, as keeping the buffer is useless for frozen strings.
Not sure if changing rb_str_freeze this way breaks compatibility
(but we should be able to safely resize for rb_fstring, at least).