From: "alexeymuranov (Alexey Muranov)" Date: 2013-08-20T18:20:32+09:00 Subject: [ruby-core:56755] [ruby-trunk - Feature #8579] Frozen string syntax Issue #8579 has been updated by alexeymuranov (Alexey Muranov). =begin Just two put in my 2 cents, i have suggested in #7791 to have an intermediate class between String and Symbol, but maybe frozen strings are better. What would you say about a new literal syntax, like, for example, |'this is a frozen string' ? Since frozen strings are likely to be used as hash keys, in simple cases the quotes may be dropped: |this_is_a_frozen_string Just a thought. =end ---------------------------------------- Feature #8579: Frozen string syntax https://bugs.ruby-lang.org/issues/8579#change-41298 Author: charliesome (Charlie Somerville) Status: Open Priority: Normal Assignee: ko1 (Koichi Sasada) Category: syntax Target version: current: 2.1.0 I'd like to propose a new type of string literal - %f(). Because Ruby strings are mutable, every time a string literal is evaluated a new String object must be duped. It's quite common to see code that stores a frozen String object into a constant which is then reused for performance reasons. Example: https://github.com/rack/rack/blob/master/lib/rack/methodoverride.rb A new %f() string literal would instead evaluate to the same frozen String object every time. The benefit of this syntax is that it removes the need to pull string literals away from where they are used. Here's an example of the proposed %f() syntax in action: def foo ["bar".object_id, %f(bar).object_id] end p foo # might print "[123, 456]" p foo # might print "[789, 456]" These string literals could also be stored into a global refcounted table for deduplication across the entire program, futher reducing memory usage. If this proposal is accepted, I can handle implementation work. -- http://bugs.ruby-lang.org/