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

ruby-changes:38918

From: normal <ko1@a...>
Date: Tue, 23 Jun 2015 06:50:49 +0900 (JST)
Subject: [ruby-changes:38918] normal:r50999 (trunk): struct.c: cache member definition in a subclass

normal	2015-06-23 06:50:31 +0900 (Tue, 23 Jun 2015)

  New Revision: 50999

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

  Log:
    struct.c: cache member definition in a subclass
    
    Since getting Qnil is already error, it is safe to use rb_attr_get.
    
    * struct.c (struct_ivar_get): cache member definition in a subclass
      Thanks to Sokolov Yura aka funny_falcon <funny.falcon@g...>
      in https://bugs.ruby-lang.org/issues/10585

  Modified files:
    trunk/ChangeLog
    trunk/struct.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50998)
+++ ChangeLog	(revision 50999)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 23 06:37:10 2015  Eric Wong  <e@8...>
+
+	* struct.c (struct_ivar_get): cache member definition in a subclass
+	  Thanks to Sokolov Yura aka funny_falcon <funny.falcon@g...>
+	  in https://bugs.ruby-lang.org/issues/10585
+
 Tue Jun 23 04:58:06 2015  Eric Wong  <e@8...>
 
 	* benchmark/bm_vm2_struct_big_href_hi.rb: new benchmark
Index: struct.c
===================================================================
--- struct.c	(revision 50998)
+++ struct.c	(revision 50999)
@@ -23,12 +23,20 @@ static VALUE struct_alloc(VALUE); https://github.com/ruby/ruby/blob/trunk/struct.c#L23
 static inline VALUE
 struct_ivar_get(VALUE c, ID id)
 {
+    VALUE orig = c;
+    VALUE ivar = rb_attr_get(c, id);
+
+    if (!NIL_P(ivar))
+	return ivar;
+
     for (;;) {
-	if (rb_ivar_defined(c, id))
-	    return rb_ivar_get(c, id);
 	c = RCLASS_SUPER(c);
 	if (c == 0 || c == rb_cStruct)
 	    return Qnil;
+	ivar = rb_attr_get(c, id);
+	if (!NIL_P(ivar)) {
+	    return rb_ivar_set(orig, id, ivar);
+	}
     }
 }
 

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

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