mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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@gmail.com> in https://bugs.ruby-lang.org/issues/10585 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50999 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8b71b4e5c5
commit
099e6e7817
2 changed files with 16 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
Tue Jun 23 06:37:10 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* struct.c (struct_ivar_get): cache member definition in a subclass
|
||||
Thanks to Sokolov Yura aka funny_falcon <funny.falcon@gmail.com>
|
||||
in https://bugs.ruby-lang.org/issues/10585
|
||||
|
||||
Tue Jun 23 04:58:06 2015 Eric Wong <e@80x24.org>
|
||||
|
||||
* benchmark/bm_vm2_struct_big_href_hi.rb: new benchmark
|
||||
|
|
12
struct.c
12
struct.c
|
@ -23,12 +23,20 @@ static VALUE struct_alloc(VALUE);
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue