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

ruby-changes:41981

From: nobu <ko1@a...>
Date: Wed, 9 Mar 2016 16:17:06 +0900 (JST)
Subject: [ruby-changes:41981] nobu:r54055 (trunk): hash.c: make duplicated hash WB protected

nobu	2016-03-09 16:17:01 +0900 (Wed, 09 Mar 2016)

  New Revision: 54055

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54055

  Log:
    hash.c: make duplicated hash WB protected
    
    * hash.c (hash_alloc_flags): allocate new hash with the flags and
      the default value.
    
    * hash.c (hash_dup): duplicate with the flags and the default
      value.
    
    * hash.c (rb_hash_dup): make the duplicated hash write-barrier
      protected.

  Modified files:
    trunk/hash.c
Index: hash.c
===================================================================
--- hash.c	(revision 54054)
+++ hash.c	(revision 54055)
@@ -369,16 +369,23 @@ rb_hash_foreach(VALUE hash, int (*func)( https://github.com/ruby/ruby/blob/trunk/hash.c#L369
 }
 
 static VALUE
-hash_alloc(VALUE klass)
+hash_alloc_flags(VALUE klass, VALUE flags, VALUE ifnone)
 {
-    NEWOBJ_OF(hash, struct RHash, klass, T_HASH | (RGENGC_WB_PROTECTED_HASH ? FL_WB_PROTECTED : 0));
+    const VALUE wb = (RGENGC_WB_PROTECTED_HASH ? FL_WB_PROTECTED : 0);
+    NEWOBJ_OF(hash, struct RHash, klass, T_HASH | wb | flags);
 
-    RHASH_SET_IFNONE((VALUE)hash, Qnil);
+    RHASH_SET_IFNONE((VALUE)hash, ifnone);
 
     return (VALUE)hash;
 }
 
 static VALUE
+hash_alloc(VALUE klass)
+{
+    return hash_alloc_flags(klass, 0, Qnil);
+}
+
+static VALUE
 empty_hash_alloc(VALUE klass)
 {
     RUBY_DTRACE_CREATE_HOOK(HASH, 0);
@@ -392,28 +399,24 @@ rb_hash_new(void) https://github.com/ruby/ruby/blob/trunk/hash.c#L399
     return hash_alloc(rb_cHash);
 }
 
-static inline VALUE
-rb_hash_dup_empty(VALUE hash)
+static VALUE
+hash_dup(VALUE hash, VALUE klass, VALUE flags)
 {
-    NEWOBJ_OF(ret, struct RHash,
-                rb_obj_class(hash),
-                (RBASIC(hash)->flags)&(T_MASK|FL_EXIVAR|FL_TAINT));
-    if (FL_TEST((hash), FL_EXIVAR))
-        rb_copy_generic_ivar((VALUE)(ret),(VALUE)(hash));
-
-    if (FL_TEST(hash, HASH_PROC_DEFAULT)) {
-        FL_SET(ret, HASH_PROC_DEFAULT);
-    }
-    RHASH_SET_IFNONE(ret, RHASH_IFNONE(hash));
-    return (VALUE)ret;
+    VALUE ret = hash_alloc_flags(klass, flags,
+				 RHASH_IFNONE(hash));
+    if (!RHASH_EMPTY_P(hash))
+	RHASH(ret)->ntbl = st_copy(RHASH(hash)->ntbl);
+    return ret;
 }
 
 VALUE
 rb_hash_dup(VALUE hash)
 {
-    VALUE ret = rb_hash_dup_empty(hash);
-    if (!RHASH_EMPTY_P(hash))
-	RHASH(ret)->ntbl = st_copy(RHASH(hash)->ntbl);
+    const VALUE flags = RBASIC(hash)->flags;
+    VALUE ret = hash_dup(hash, rb_obj_class(hash),
+			 flags & (FL_EXIVAR|FL_TAINT|HASH_PROC_DEFAULT));
+    if (flags & FL_EXIVAR)
+        rb_copy_generic_ivar(ret, hash);
     return ret;
 }
 

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

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