From d9987aa704e5b94983aac43804269b52902e7fc4 Mon Sep 17 00:00:00 2001 From: akr Date: Wed, 27 Jun 2007 16:45:56 +0000 Subject: [PATCH] * parse.y (rb_intern2): don't allocate a string object at first. [ruby-dev:31064] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ parse.y | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0879f1968a..2b1184a8a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Thu Jun 28 01:44:31 2007 Tanaka Akira + + * parse.y (rb_intern2): don't allocate a string object at first. + [ruby-dev:31064] + Thu Jun 28 01:24:02 2007 Koichi Sasada * bootstraptest/runner.rb: fix to show file name. diff --git a/parse.y b/parse.y index 2b880f7bdd..28354805ac 100644 --- a/parse.y +++ b/parse.y @@ -8389,11 +8389,17 @@ ID 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; @@ -8453,6 +8459,7 @@ rb_intern2(const char *name, long len) 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);