[#85940] [Ruby trunk Bug#14578] Forking a child process inside of a mutex crashes the ruby interpreter — ben.govero@...
Issue #14578 has been reported by bengovero (Ben Govero).
3 messages
2018/03/05
[#86205] [Ruby trunk Feature#14618] Add display width method to String for CLI — aycabta@...
Issue #14618 has been reported by aycabta (aycabta .).
3 messages
2018/03/19
[#86366] Re: [ruby-cvs:70102] usa:r63008 (trunk): get rid of test error/failure on Windows introduced at r62955 — Eric Wong <normalperson@...>
usa@ruby-lang.org wrote:
3 messages
2018/03/28
[ruby-core:86320] [Ruby trunk Bug#14624] #{nil} allocates a fresh empty string each time
From:
dwelch@...
Date:
2018-03-27 04:17:13 UTC
List:
ruby-core #86320
Issue #14624 has been updated by bumblingbear (Dillon Welch).
Closer to the string interpolation optimization part. The problem with "#{nil}" is that it allocates two empty strings each time. I feel like it would be possible to do this with zero/one allocation. I don't know what the underlying code looks like, but the logic I'm thinking of is something like
```
def interpolate(obj)
if obj == nil
''
else
obj.to_s # assuming this is current behavior
end
end
```
phluid61 (Matthew Kerwin) wrote:
> I'm confused; are you proposing that `nil.to_s` returns the same String object every time, or that string interpolation detects a `nil` object and optimises it?
>
> A lot of times I rely on `"#{foo}"` returning a new String object that contains a copy of the #to_s of `foo`, so it seems to me like spec that `"#{nil}"` returns a new empty string every time.
----------------------------------------
Bug #14624: #{nil} allocates a fresh empty string each time
https://bugs.ruby-lang.org/issues/14624#change-71239
* 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>