Issue #14624 has been updated by bumblingbear (Dillon Welch).


That sounds fine to me!

Hanmac (Hans Mackowiak) wrote:
> i have a problem with that, what if someone might do:
> 
> ~~~ ruby
> x = obj.to_s
> x << obj2.to_s
> ~~~
> 
> then it might be nil, return a frozen string and it would do a RuntimeError
> 
> better imo would be that if "#{nil}" would do a check if to_s is overwritten or redefined and if not do other magic



----------------------------------------
Bug #14624: #{nil} allocates a fresh empty string each time
https://bugs.ruby-lang.org/issues/14624#change-71237

* Author: bumblingbear (Dillon Welch)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
This causes a bunch of unnecessary string allocations in the following scenario: "#{'rails' unless boolean_condition} is great". Each time this line is called when boolean_condition is true, it evaluates to nil and when nil is interpolated into a string it allocates an empty string. Ideally, the behavior of nil.to_s would reference a frozen empty string that wouldn't need to be reallocated each time.



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>