ruby-changes:31889
From: tmm1 <ko1@a...>
Date: Tue, 3 Dec 2013 12:41:04 +0900 (JST)
Subject: [ruby-changes:31889] tmm1:r43968 (trunk): * string.c (rb_fstring): Use st_update instead of st_lookup +
tmm1 2013-12-03 12:40:56 +0900 (Tue, 03 Dec 2013) New Revision: 43968 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43968 Log: * string.c (rb_fstring): Use st_update instead of st_lookup + st_insert. * string.c (fstr_update_callback): New callback for st_update. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 43967) +++ ChangeLog (revision 43968) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Tue Dec 3 12:20:21 2013 Aman Gupta <ruby@t...> + + * string.c (rb_fstring): Use st_update instead of st_lookup + + st_insert. + * string.c (fstr_update_callback): New callback for st_update. + Tue Dec 3 12:17:59 2013 Nobuyoshi Nakada <nobu@r...> * lib/rdoc/constant.rb (RDoc::Constant#documented?): workaround for Index: string.c =================================================================== --- string.c (revision 43967) +++ string.c (revision 43968) @@ -132,22 +132,16 @@ static const struct st_hash_type fstring https://github.com/ruby/ruby/blob/trunk/string.c#L132 rb_str_hash, }; -VALUE -rb_fstring(VALUE str) +static int +fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existing) { - st_data_t fstr; - Check_Type(str, T_STRING); - - if (FL_TEST(str, RSTRING_FSTR)) - return str; - - if (st_lookup(frozen_strings, (st_data_t)str, &fstr)) { - str = (VALUE)fstr; + VALUE *fstr = (VALUE *)arg; + if (existing) { /* because of lazy sweep, str may be unmaked already and swept * at next time */ - rb_gc_resurrect(str); - } - else { + rb_gc_resurrect(*fstr = *key); + } else { + VALUE str = *key; if (STR_SHARED_P(str)) { /* str should not be shared */ str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str)); @@ -157,9 +151,23 @@ rb_fstring(VALUE str) https://github.com/ruby/ruby/blob/trunk/string.c#L151 str = rb_str_new_frozen(str); } RBASIC(str)->flags |= RSTRING_FSTR; - st_insert(frozen_strings, str, str); + *fstr = *key = str; } - return str; + + return ST_CONTINUE; +} + +VALUE +rb_fstring(VALUE str) +{ + VALUE fstr = Qnil; + Check_Type(str, T_STRING); + + if (FL_TEST(str, RSTRING_FSTR)) + return str; + + st_update(frozen_strings, (st_data_t)str, fstr_update_callback, (st_data_t)&fstr); + return fstr; } static int -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/