* string.c (rb_fstring): Use st_update instead of st_lookup +
st_insert. * string.c (fstr_update_callback): New callback for st_update. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43968 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
41a73480c6
commit
6edaf997e3
@ -1,3 +1,9 @@
|
|||||||
|
Tue Dec 3 12:20:21 2013 Aman Gupta <ruby@tmm1.net>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Tue Dec 3 12:17:59 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/rdoc/constant.rb (RDoc::Constant#documented?): workaround for
|
* lib/rdoc/constant.rb (RDoc::Constant#documented?): workaround for
|
||||||
|
38
string.c
38
string.c
@ -132,22 +132,16 @@ static const struct st_hash_type fstring_hash_type = {
|
|||||||
rb_str_hash,
|
rb_str_hash,
|
||||||
};
|
};
|
||||||
|
|
||||||
VALUE
|
static int
|
||||||
rb_fstring(VALUE str)
|
fstr_update_callback(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
|
||||||
{
|
{
|
||||||
st_data_t fstr;
|
VALUE *fstr = (VALUE *)arg;
|
||||||
Check_Type(str, T_STRING);
|
if (existing) {
|
||||||
|
|
||||||
if (FL_TEST(str, RSTRING_FSTR))
|
|
||||||
return str;
|
|
||||||
|
|
||||||
if (st_lookup(frozen_strings, (st_data_t)str, &fstr)) {
|
|
||||||
str = (VALUE)fstr;
|
|
||||||
/* because of lazy sweep, str may be unmaked already and swept
|
/* because of lazy sweep, str may be unmaked already and swept
|
||||||
* at next time */
|
* at next time */
|
||||||
rb_gc_resurrect(str);
|
rb_gc_resurrect(*fstr = *key);
|
||||||
}
|
} else {
|
||||||
else {
|
VALUE str = *key;
|
||||||
if (STR_SHARED_P(str)) {
|
if (STR_SHARED_P(str)) {
|
||||||
/* str should not be shared */
|
/* str should not be shared */
|
||||||
str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
|
str = rb_enc_str_new(RSTRING_PTR(str), RSTRING_LEN(str), STR_ENC_GET(str));
|
||||||
@ -157,9 +151,23 @@ rb_fstring(VALUE str)
|
|||||||
str = rb_str_new_frozen(str);
|
str = rb_str_new_frozen(str);
|
||||||
}
|
}
|
||||||
RBASIC(str)->flags |= RSTRING_FSTR;
|
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
|
static int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user