From: Eric Wong Date: 2018-02-14T22:45:54+00:00 Subject: [ruby-core:85564] Re: [Ruby trunk Bug#14475] String de-duplication is broken in files with frozen_string_literal: true sam.saffron@gmail.com wrote: > "If the string is frozen, then return the string itself." > > Yeah I do not agree with this documentation, I think it should be changed. > > Trouble is that there is no simple way to de-duplicate > unconditionally without either inefficiency or side effects: Yeah, I originally proposed a new method back in the day but compromised with String#-@ > Say `x` is an arbitrary string (either frozen or unfrozen) : > > ``` > x = -x # may return a non fstring > > x = -+x # will return fstring, but makes an unneeded copy > > x = -x.dup # fstring again, uneeded copy Maybe these can be optimized in the VM (still ugly, and redefinition checks aren't free, either). > x = x.frozen? ? -+x : -x # too verbose > ``` > > Instead why not change it so `-` deduped unconditionally? At this point, it may break existing code :< Unsubscribe: