msgpack-ruby icon indicating copy to clipboard operation
msgpack-ruby copied to clipboard

Restore referenced buffers feature

Open casperisfine opened this issue 2 years ago • 0 comments

Restore referenced buffers feature

I think this feature was accidentally removed in https://github.com/msgpack/msgpack-ruby/pull/213

On the MRI versions we support rb_str_dup won't copy the string but return a shared string. So it's safe to always append a reference when we are provided a string.

So instead of copying the RString content into the buffer, we simply keep a reference to it, and point to its RSTRING_PTR().

From some quick benchmarking, it doesn't seem to make a very big difference, but since we already have all the facilities for it, might as well use it.

FYI @chrisseaton (for when you get back, no rush)

casperisfine avatar Sep 13 '22 15:09 casperisfine