From: john@... Date: 2019-06-26T03:00:24+00:00 Subject: [ruby-core:93367] [Ruby trunk Bug#15960] rb_fstring should resize capacity [patch] Issue #15960 has been reported by jhawthorn (John Hawthorn). ---------------------------------------- Bug #15960: rb_fstring should resize capacity [patch] https://bugs.ruby-lang.org/issues/15960 * Author: jhawthorn (John Hawthorn) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: * Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN ---------------------------------------- https://github.com/ruby/ruby/pull/2256 When a string is `#frozen`, it's capacity is resized to fit (if it is much larger), since we know it will no longer be mutated we'd like to save the space. > puts ObjectSpace.dump(String.new("a"*30, capacity: 1000)) {"type":"STRING", "class":"0x7feaf00b7bf0", "bytesize":30, "capacity":1000, "value":"... > puts ObjectSpace.dump(String.new("a"*30, capacity: 1000).freeze) {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "bytesize":30, "value":"... (`ObjectSpace.dump` doesn't show capacity if capacity is equal to bytesize) Previously, if we dedup into an fstring, using `String#-@`, capacity would not be reduced. > puts ObjectSpace.dump(-String.new("a"*30, capacity: 1000)) {"type":"STRING", "class":"0x7feaf00b7bf0", "frozen":true, "fstring":true, "bytesize":30, "capacity":1000, "value":"... I've attached a commit to make `rb_fstring` call `rb_str_resize`, the same as `rb_str_freeze` does. ---Files-------------------------------- 2256.patch (2.28 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: