From dffae9a1f978d5ee5130475f4ea725865ead1730 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 5 Sep 2013 08:25:56 +0000 Subject: [PATCH] string.c: reduce objects in rb_fstring * string.c (rb_fstring, rb_str_free): use st_data_t instead of VALUE. * string.c (rb_fstring): get rid of duplicating already frozen object. * parse.y (str_suffix_gen): freeze in advance to reduce objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42846 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ parse.y | 1 + string.c | 19 +++++++++++-------- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5664016f15..1d97788d0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Thu Sep 5 17:25:49 2013 Nobuyoshi Nakada + + * string.c (rb_fstring, rb_str_free): use st_data_t instead of VALUE. + + * string.c (rb_fstring): get rid of duplicating already frozen object. + + * parse.y (str_suffix_gen): freeze in advance to reduce objects. + Thu Sep 5 14:01:22 2013 Eric Hodel * lib/optparse.rb: The Integer acceptable now allows binary and diff --git a/parse.y b/parse.y index d17591253c..6cfb9421d2 100644 --- a/parse.y +++ b/parse.y @@ -8561,6 +8561,7 @@ str_suffix_gen(struct parser_params *parser, NODE *node, long opt) #endif #if STR_OPTION_FROZEN if (opt & STR_OPTION_FROZEN) { + OBJ_FREEZE(node->nd_lit); node->nd_lit = rb_fstring(node->nd_lit); nd_set_type(node, NODE_LIT); } diff --git a/string.c b/string.c index 7ee4730930..c1366e834e 100644 --- a/string.c +++ b/string.c @@ -141,14 +141,16 @@ static const struct st_hash_type fstring_hash_type = { VALUE rb_fstring(VALUE str) { - VALUE fstr; - if (!st_lookup(frozen_strings, (st_data_t)str, (st_data_t*)&fstr)) { - fstr = rb_str_dup(str); - OBJ_FREEZE(fstr); - RBASIC(fstr)->flags |= RSTRING_FSTR; - st_insert(frozen_strings, fstr, fstr); + st_data_t fstr; + if (st_lookup(frozen_strings, (st_data_t)str, &fstr)) { + str = (VALUE)fstr; } - return fstr; + else { + str = rb_str_new_frozen(str); + RBASIC(str)->flags |= RSTRING_FSTR; + st_insert(frozen_strings, str, str); + } + return str; } static inline int @@ -859,7 +861,8 @@ void rb_str_free(VALUE str) { if (FL_TEST(str, RSTRING_FSTR)) { - st_delete(frozen_strings, (st_data_t*)&str, NULL); + st_data_t fstr = (st_data_t)str; + st_delete(frozen_strings, &fstr, NULL); } if (!STR_EMBED_P(str) && !STR_SHARED_P(str)) { xfree(RSTRING(str)->as.heap.ptr);