Project

General

Profile

Actions

Feature #14624

open

#{nil} allocates a fresh empty string each time

Added by bumblingbear (Dillon Welch) about 6 years ago. Updated almost 6 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:86257]

Description

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0