[#8815] Segfault in libc strlen, via rb_str_new2 — "Sean E. Russell" <ser@...>

Howdy,

12 messages 2006/09/09
[#8817] Re: Segfault in libc strlen, via rb_str_new2 — Eric Hodel <drbrain@...7.net> 2006/09/09

On Sep 8, 2006, at 10:10 PM, Sean E. Russell wrote:

Re: Literal inconsistency

From: Christian Neukirchen <chneukirchen@...>
Date: 2006-09-04 14:28:20 UTC
List: ruby-core #8789
Calamitas <calamitates@gmail.com> writes:

> Hi,
>
> This surprised me today:
>
>  irb(main):014:0> 2.times { puts "hello".object_id }
>  -606413918
>  -606413938
>  => 2
>  irb(main):015:0> 2.times { puts /hello/.object_id }
>  -606420168
>  -606420168
>  => 2
>
> The regexp could be compiled once while parsing and a new Regexp
> object could be created on each execution with a speed hit comparable
> to string literals (which I suppose is acceptable.)

I don't see the inconsistency.  Regexps are immutable anyway, so this
optimization is useful.  You probably wanted Regexp.new("hello")?

> Peter
-- 
Christian Neukirchen  <chneukirchen@gmail.com>  http://chneukirchen.org

In This Thread