ruby-changes:28387
From: nobu <ko1@a...>
Date: Wed, 24 Apr 2013 14:22:09 +0900 (JST)
Subject: [ruby-changes:28387] nobu:r40439 (trunk): parse.y: setup_fake_str
nobu 2013-04-24 14:22:00 +0900 (Wed, 24 Apr 2013) New Revision: 40439 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40439 Log: parse.y: setup_fake_str * parse.y (setup_fake_str): extract function. Modified files: trunk/parse.y Index: parse.y =================================================================== --- parse.y (revision 40438) +++ parse.y (revision 40439) @@ -10189,18 +10189,23 @@ sym_check_asciionly(VALUE str) https://github.com/ruby/ruby/blob/trunk/parse.y#L10189 */ static ID intern_str(VALUE str); +static VALUE +setup_fake_str(struct RString *fake_str, const char *name, long len) +{ + fake_str->basic.flags = T_STRING|RSTRING_NOEMBED; + fake_str->basic.klass = rb_cString; + fake_str->as.heap.len = len; + fake_str->as.heap.ptr = (char *)name; + fake_str->as.heap.aux.capa = len; + return (VALUE)fake_str; +} + ID rb_intern3(const char *name, long len, rb_encoding *enc) { - VALUE str; st_data_t data; struct RString fake_str; - fake_str.basic.flags = T_STRING|RSTRING_NOEMBED; - fake_str.basic.klass = rb_cString; - fake_str.as.heap.len = len; - fake_str.as.heap.ptr = (char *)name; - fake_str.as.heap.aux.capa = len; - str = (VALUE)&fake_str; + VALUE str = setup_fake_str(&fake_str, name, len); rb_enc_associate(str, enc); OBJ_FREEZE(str); @@ -10523,13 +10528,8 @@ rb_check_id(volatile VALUE *namep) https://github.com/ruby/ruby/blob/trunk/parse.y#L10528 if (rb_is_attrset_name(name)) { struct RString fake_str; - const VALUE localname = (VALUE)&fake_str; /* make local name by chopping '=' */ - fake_str.basic.flags = T_STRING|RSTRING_NOEMBED; - fake_str.basic.klass = rb_cString; - fake_str.as.heap.len = RSTRING_LEN(name) - 1; - fake_str.as.heap.ptr = RSTRING_PTR(name); - fake_str.as.heap.aux.capa = fake_str.as.heap.len; + const VALUE localname = setup_fake_str(&fake_str, RSTRING_PTR(name), RSTRING_LEN(name) - 1); rb_enc_copy(localname, name); OBJ_FREEZE(localname); @@ -10547,12 +10547,7 @@ rb_check_id_cstr(const char *ptr, long l https://github.com/ruby/ruby/blob/trunk/parse.y#L10547 { st_data_t id; struct RString fake_str; - const VALUE name = (VALUE)&fake_str; - fake_str.basic.flags = T_STRING|RSTRING_NOEMBED; - fake_str.basic.klass = rb_cString; - fake_str.as.heap.len = len; - fake_str.as.heap.ptr = (char *)ptr; - fake_str.as.heap.aux.capa = len; + const VALUE name = setup_fake_str(&fake_str, ptr, len); rb_enc_associate(name, enc); sym_check_asciionly(name); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/