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

ruby-changes:31907

From: tmm1 <ko1@a...>
Date: Wed, 4 Dec 2013 13:05:21 +0900 (JST)
Subject: [ruby-changes:31907] tmm1:r43986 (trunk): * string.c (fstr_update_callback): Improve implementation in r43968

tmm1	2013-12-04 13:05:13 +0900 (Wed, 04 Dec 2013)

  New Revision: 43986

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

  Log:
    * string.c (fstr_update_callback): Improve implementation in r43968
      based on feedback from @nagachika. In the existing case, we can
      return ST_STOP to prevent any hash modification. In the !existing
      case, set both key and value to the fstr.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43985)
+++ ChangeLog	(revision 43986)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec  4 12:57:24 2013  Aman Gupta <ruby@t...>
+
+	* string.c (fstr_update_callback): Improve implementation in r43968
+	  based on feedback from @nagachika. In the existing case, we can
+	  return ST_STOP to prevent any hash modification. In the !existing
+	  case, set both key and value to the fstr.
+
 Wed Dec  4 12:47:54 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/delegate.rb (Delegator#method_missing): ignore the target if not
Index: string.c
===================================================================
--- string.c	(revision 43985)
+++ string.c	(revision 43986)
@@ -137,23 +137,24 @@ fstr_update_callback(st_data_t *key, st_ https://github.com/ruby/ruby/blob/trunk/string.c#L137
 {
     VALUE *fstr = (VALUE *)arg;
     if (existing) {
-	/* because of lazy sweep, str may be unmaked already and swept
+	/* because of lazy sweep, str may be unmarked already and swept
 	 * at next time */
 	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));
-	    OBJ_FREEZE(str);
-	}
-	else {
-	    str = rb_str_new_frozen(str);
-	}
-	RBASIC(str)->flags |= RSTRING_FSTR;
-	*fstr = *key = str;
+	return ST_STOP;
     }
 
+    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));
+	OBJ_FREEZE(str);
+    }
+    else {
+	str = rb_str_new_frozen(str);
+    }
+    RBASIC(str)->flags |= RSTRING_FSTR;
+
+    *key = *value = *fstr = str;
     return ST_CONTINUE;
 }
 

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

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