Project

General

Profile

Actions

Feature #26561

closed

Enable frozen string literals

Added by Pavel Rosický over 7 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Performance
Target version:
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:

Description

Hi, Ruby 2.3 introduced support for frozen string literals

Pros
  • less memory consumption
  • performance (less GC preasure)
  • safer code
Cons
  • mutable functions like force_encoding or gsub! can't be called on frozen strings anymore, this may cause incompatibility with some plugins, but it's very easy to fix and still maintain the backwards compatibility
  • a magic comment has to be added at the top of each rb file :-(

More information
https://www.pluralsight.com/blog/software-development/ruby-2-3--working-with-immutable-strings-

Many popular gems and libraries already did this - for example:
https://github.com/rails/rails/pull/29655
https://github.com/mikel/mail/pull/970

I attached a patch based on master that passes all tests.
There're some garbage changes like removed whitespaces, I'll clean it up if it's approved.

What do you think?


Files

frozen_string_literals.patch (541 KB) frozen_string_literals.patch Pavel Rosický, 2017-07-27 22:12
frozen.patch (86.8 KB) frozen.patch Pavel Rosický, 2019-03-06 20:19

Related issues

Related to Redmine - Patch #31004: Decode hexadecimal-encoded literals in order to be frozen string literals friendlyClosedGo MAEDA

Actions
Related to Redmine - Defect #31052: Download unified diff throws "can't modify frozen String" error.ClosedGo MAEDA

Actions
Related to Redmine - Patch #31059: Use #b shortcut instead of #force_encodingClosedGo MAEDA

Actions
Related to Redmine - Defect #32071: FrozenError in assert_save in test/test_helper.rbClosed

Actions
Related to Redmine - Defect #31508: Add missing frozen strings and copyrightsClosedGo MAEDA

Actions
Related to Redmine - Defect #33021: [v.4.0.5-stable] Internal Server Error 500 when accessing 'repository' tabClosed

Actions
Actions

Also available in: Atom PDF