[#1026] Is this a bug? — Dave Thomas <Dave@...>

18 messages 2000/01/03

[#1084] Infinite loop — Dave Thomas <Dave@...>

17 messages 2000/01/11

[#1104] The value of while... — Dave Thomas <Dave@...>

24 messages 2000/01/11

[ruby-talk:01193] Semantics of chomp/chop

From: Dave Thomas <Dave@...>
Date: 2000-01-28 16:50:51 UTC
List: ruby-talk #1193
I was wondering about the semantics of Kernel#chomp and
Kernel#chop. Take 'chomp'

     static VALUE
     rb_f_chomp(argc, argv)
         int argc;
         VALUE *argv;
     {
         VALUE str = rb_str_dup(uscore_get());
         if (!NIL_P(rb_str_chomp_bang(argc, argv, str))) {
             rb_lastline_set(str);
         }
         return str;
     }

If no change is make to $_, a new copy of it is returned. If a change
_is_ made, then it becomes the copy, which is returned.

This additional rb_str_dup looks like it's trying to avoid some kind
of aliasing problem. Is the extra copy necessary?


Regards


Dave

In This Thread

Prev Next