[#70257] [Ruby trunk - Feature #11420] [Open] Introduce ID key table into MRI — ko1@...

Issue #11420 has been reported by Koichi Sasada.

11 messages 2015/08/06

[ruby-core:70494] [Ruby trunk - Feature #8948] [Assigned] Frozen regex

From: ko1@...
Date: 2015-08-21 05:31:50 UTC
List: ruby-core #70494
Issue #8948 has been updated by Koichi Sasada.

Status changed from Feedback to Assigned

There are two options:

(1) Freeze only literal regexps
(2) Freeze all of regexps

I like (2) because I have no idea to change regexp objects.

History of "Frozen":

* Ruby 2.0
  * Integer (Bignum, Fixnum) https://bugs.ruby-lang.org/issues/3222
  * Float https://bugs.ruby-lang.org/issues/6936
* Ruby 2.1
  * nil/true/false https://bugs.ruby-lang.org/issues/8923
* Ruby 2.2
  * Symbols https://bugs.ruby-lang.org/issues/8906


----------------------------------------
Feature #8948: Frozen regex
https://bugs.ruby-lang.org/issues/8948#change-53895

* Author: Tsuyoshi Sawada
* Status: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumoto
----------------------------------------
=begin
I see that frozen string was accepted for Ruby 2.1, and frozen array and hash are proposed in https://bugs.ruby-lang.org/issues/8909. I feel there is even more use case for a frozen regex, i.e., a regex literal that generates a regex only once. It is frequent to have a regex within a frequently repeated portion of code, and generating the same regex each time is a waste of resource. At the moment, we can have a code like:

    class Foo
      RE1 = /pattern1/
      RE2 = /pattern1/
      RE3 = /pattern1/
      def classify
        case self
        when RE1 then 1
        when RE2 then 2
        when RE3 then 3
        else 4
        end
      end
    end

but suppose we have a frozen `Regexp` literal `//f`. Then we can write like:

    class Foo
      def classify
        case self
        when /pattern1/f then 1
        when /pattern1/f then 2
        when /pattern1/f then 3
        else 4
        end
      end
    end

=end



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

In This Thread