String allocation in rb_intern

rb_intern e$B$,Kh2s!“e(B(e$B$9$G$K%7%s%%k$,$”$C$F$be(B) String
e$B%*%V%8%'e(B
e$B%/%[email protected]@.$7$^$9!#e(B

e$B$=$&$7$J$$$h$&$K$9$k$U$6$1$?%3!<%I$r$D$$=q$$$F$7$^$C$?$N$G$He(B
e$B$j$"$($:Aw$C$F$*$-$^$9!#e(B

Index: parse.y

— parse.y (e$B%j%S%8%g%se(B 12629)
+++ parse.y (e$B:n6H%3%T!<e(B)
@@ -8390,11 +8390,17 @@
rb_intern2(const char *name, long len)
{
const char *m = name;

  • VALUE str = rb_str_new(name, len);
  • VALUE str;
    ID id;
    int last;
  • struct RString fake_str;
  • fake_str.basic.flags = T_STRING|RSTRING_NOEMBED|FL_FREEZE;
  • fake_str.basic.klass = rb_cString;
  • fake_str.as.heap.len = len;
  • fake_str.as.heap.ptr = name;
  • fake_str.as.heap.aux.capa = len;
  • if (st_lookup(global_symbols.sym_id, (st_data_t)str, (st_data_t
    *)&id))
  • if (st_lookup(global_symbols.sym_id, (st_data_t)&fake_str,
    (st_data_t *)&id))
    return id;

    last = len-1;
    @@ -8454,6 +8460,7 @@
    new_id:
    id |= ++global_symbols.last_id << ID_SCOPE_SHIFT;
    id_register:

  • str = rb_str_new(name, len);
    OBJ_FREEZE(str);
    st_add_direct(global_symbols.sym_id, (st_data_t)str, id);
    st_add_direct(global_symbols.id_str, id, (st_data_t)str);

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:31064] string allocation in rb_intern”
on Wed, 27 Jun 2007 02:22:30 +0900, Tanaka A. [email protected]
writes:

|rb_intern e$B$,Kh2s!“e(B(e$B$9$G$K%7%s%%k$,$”$C$F$be(B) String e$B%%V%8%'e(B
|e$B%/%[email protected]@.$7$^$9!#e(B
|
|e$B$=$&$7$J$$$h$&$K$9$k$U$6$1$?%3!<%I$r$D$$=q$$$F$7$^$C$?$N$G$He(B
|e$B$j$"$($:Aw$C$F$
$-$^$9!#e(B

e$B$3$&$$$&!V$U$6$1$?!W%3!<%I$OBg9%$-$J$N$G%3%_%C%[email protected]$1e(B
e$B$^$;$s$+!)e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs