diff options
author | John Hawthorn <john@hawthorn.email> | 2019-06-26 09:52:30 -0700 |
---|---|---|
committer | Aaron Patterson <tenderlove@ruby-lang.org> | 2019-08-09 16:33:53 -0700 |
commit | 9d298b9dab831f966ea4bf365c712161118dd631 (patch) | |
tree | cafabbc52374a8f11e4450d19a1cad3809d29acd /GPL | |
parent | b1678338e545589540b1dd85dee6a18fd98aa8ed (diff) | |
download | ruby-9d298b9dab831f966ea4bf365c712161118dd631.tar.gz |
Allow Array#join to allocate smaller strings
rb_str_buf_new always allocates at least 127 bytes of capacity, even
when less is requested.
> ObjectSpace.dump(%w[a b c].join)
{"address":"0x7f935f06ebf0", "type":"STRING", "class":"0x7f935d8b7bb0", "bytesize":3, "capacity":127, "value":"abc", "encoding":"UTF-8", "memsize":168, "flags":{"wb_protected":true}}
Instead, by using rb_str_new and then setting the length to 0, we can
allocate the exact amount of memory needed, without extra capacity.
> ObjectSpace.dump(%w[a b c].join)
{"address":"0x7f903fcab530", "type":"STRING", "class":"0x7f903f8b7988", "embedded":true, "bytesize":3, "value":"abc", "encoding":"UTF-8", "memsize":40, "flags":{"wb_protected":true}}
Diffstat (limited to 'GPL')
0 files changed, 0 insertions, 0 deletions