1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

class.c: remove recursion

* class.c (rewrite_cref_stack): remove recursion.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42848 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-09-05 15:05:20 +00:00
parent 7eafeaa313
commit bbbc8b57eb
2 changed files with 20 additions and 13 deletions

View file

@ -1,3 +1,7 @@
Fri Sep 6 00:05:14 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* class.c (rewrite_cref_stack): remove recursion.
Thu Sep 5 18:05:00 2013 Charlie Somerville <charliesome@ruby-lang.org>
* string.c (fstring_cmp): take string encoding into account when

29
class.c
View file

@ -231,22 +231,23 @@ rb_class_new(VALUE super)
return rb_class_boot(super);
}
static NODE*
rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass)
static void
rewrite_cref_stack(NODE *node, VALUE old_klass, VALUE new_klass, NODE **new_cref_ptr)
{
NODE *new_node;
if (!node) {
return NULL;
}
if (node->nd_clss == old_klass) {
new_node = NEW_CREF(new_klass);
new_node->nd_next = node->nd_next;
}
else {
while (node) {
if (node->nd_clss == old_klass) {
new_node = NEW_CREF(new_klass);
new_node->nd_next = node->nd_next;
*new_cref_ptr = new_node;
return;
}
new_node = NEW_CREF(node->nd_clss);
new_node->nd_next = rewrite_cref_stack(node->nd_next, old_klass, new_klass);
node = node->nd_next;
*new_cref_ptr = new_node;
new_cref_ptr = &new_node->nd_next;
}
return new_node;
*new_cref_ptr = NULL;
}
static void
@ -255,9 +256,11 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
VALUE newiseqval;
if (me->def && me->def->type == VM_METHOD_TYPE_ISEQ) {
rb_iseq_t *iseq;
NODE *new_cref;
newiseqval = rb_iseq_clone(me->def->body.iseq->self, klass);
GetISeqPtr(newiseqval, iseq);
OBJ_WRITE(iseq->self, &iseq->cref_stack, rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass));
rewrite_cref_stack(me->def->body.iseq->cref_stack, me->klass, klass, &new_cref);
OBJ_WRITE(iseq->self, &iseq->cref_stack, new_cref);
rb_add_method(klass, mid, VM_METHOD_TYPE_ISEQ, iseq, me->flag);
RB_GC_GUARD(newiseqval);
}