[前][次][番号順一覧][スレッド一覧]

ruby-changes:30767

From: nobu <ko1@a...>
Date: Thu, 5 Sep 2013 17:26:05 +0900 (JST)
Subject: [ruby-changes:30767] nobu:r42846 (trunk): string.c: reduce objects in rb_fstring

nobu	2013-09-05 17:25:56 +0900 (Thu, 05 Sep 2013)

  New Revision: 42846

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42846

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/parse.y
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42845)
+++ ChangeLog	(revision 42846)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Sep  5 17:25:49 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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  <drbrain@s...>
 
 	* lib/optparse.rb:  The Integer acceptable now allows binary and
Index: string.c
===================================================================
--- string.c	(revision 42845)
+++ string.c	(revision 42846)
@@ -141,14 +141,16 @@ static const struct st_hash_type fstring https://github.com/ruby/ruby/blob/trunk/string.c#L141
 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 https://github.com/ruby/ruby/blob/trunk/string.c#L861
 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);
Index: parse.y
===================================================================
--- parse.y	(revision 42845)
+++ parse.y	(revision 42846)
@@ -8561,6 +8561,7 @@ str_suffix_gen(struct parser_params *par https://github.com/ruby/ruby/blob/trunk/parse.y#L8561
 #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);
 	}

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]