Skip to content
Browse files

remove mrb_exec_recursive

  • Loading branch information...
1 parent 4e46abb commit 80c8908c4e6672670a0fef426baa6e79d1dcd518 @matz matz committed Jun 3, 2012
Showing with 30 additions and 60 deletions.
  1. +12 −21 src/range.c
  2. +18 −39 src/struct.c
View
33 src/range.c
@@ -29,9 +29,6 @@
#define RANGE_CLASS (mrb_class_obj_get(mrb, "Range"))
-mrb_value mrb_exec_recursive_paired(mrb_state *mrb, mrb_value (*func) (mrb_state *, mrb_value, mrb_value, int),
- mrb_value obj, mrb_value paired_obj, void* arg);
-
mrb_value
mrb_range_new(mrb_state *mrb, mrb_value beg, mrb_value end, int excl)
{
@@ -397,23 +394,6 @@ range_inspect(mrb_state *mrb, mrb_value range)
return inspect_range(mrb, range, range, 0);
}
-static mrb_value
-recursive_eql(mrb_state *mrb, mrb_value range, mrb_value obj, int recur)
-{
- struct RRange *r = mrb_range_ptr(range);
- struct RRange *o = mrb_range_ptr(obj);
-
- if (recur) return mrb_true_value(); /* Subtle! */
- if (!mrb_eql(mrb, r->edges->beg, o->edges->beg))
- return mrb_false_value();
- if (!mrb_eql(mrb, r->edges->end, o->edges->end))
- return mrb_false_value();
-
- if (r->excl != o->excl)
- return mrb_false_value();
- return mrb_true_value();
-}
-
/* 15.2.14.4.14(x) */
/*
* call-seq:
@@ -433,13 +413,24 @@ static mrb_value
range_eql(mrb_state *mrb, mrb_value range)
{
mrb_value obj;
+ struct RRange *r, *o;
mrb_get_args(mrb, "o", &obj);
if (mrb_obj_equal(mrb, range, obj))
return mrb_true_value();
if (!mrb_obj_is_kind_of(mrb, obj, RANGE_CLASS))
return mrb_false_value();
- return mrb_exec_recursive_paired(mrb, recursive_eql, range, obj, &obj);
+
+ r = mrb_range_ptr(range);
+ if (obj.tt != MRB_TT_RANGE) return mrb_false_value();
+ o = mrb_range_ptr(obj);
+ if (!mrb_eql(mrb, r->edges->beg, o->edges->beg))
+ return mrb_false_value();
+ if (!mrb_eql(mrb, r->edges->end, o->edges->end))
+ return mrb_false_value();
+ if (r->excl != o->excl)
+ return mrb_false_value();
+ return mrb_true_value();
}
/* 15.2.14.4.15(x) */
View
57 src/struct.c
@@ -15,10 +15,6 @@
#ifdef INCLUDE_REGEXP
#include "encoding.h"
#endif
-mrb_sym rb_frame_this_func(mrb_state *mrb);
-mrb_sym mrb_frame_callee(mrb_state *mrb);
-mrb_value mrb_exec_recursive_paired(mrb_state *mrb, mrb_value (*func) (mrb_state *, mrb_value, mrb_value, int),
- mrb_value obj, mrb_value paired_obj, void* arg);
#include "mruby/numeric.h"
#include "mruby/hash.h"
@@ -688,22 +684,6 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s)
return RSTRUCT_PTR(s)[i] = val;
}
-static mrb_value
-recursive_equal(mrb_state *mrb, mrb_value s, mrb_value s2, int recur)
-{
- mrb_value *ptr, *ptr2;
- long i, len;
-
- if (recur) return mrb_true_value(); /* Subtle! */
- ptr = RSTRUCT_PTR(s);
- ptr2 = RSTRUCT_PTR(s2);
- len = RSTRUCT_LEN(s);
- for (i=0; i<len; i++) {
- if (!mrb_equal(mrb, ptr[i], ptr2[i])) return mrb_false_value();
- }
- return mrb_true_value();
-}
-
/* 15.2.18.4.1 */
/*
* call-seq:
@@ -726,6 +706,8 @@ static mrb_value
mrb_struct_equal(mrb_state *mrb, mrb_value s)
{
mrb_value s2;
+ mrb_value *ptr, *ptr2;
+ long i, len;
mrb_get_args(mrb, "o", &s2);
if (mrb_obj_equal(mrb, s, s2)) return mrb_true_value();
@@ -734,24 +716,13 @@ mrb_struct_equal(mrb_state *mrb, mrb_value s)
if (RSTRUCT_LEN(s) != RSTRUCT_LEN(s2)) {
mrb_bug("inconsistent struct"); /* should never happen */
}
-
- return mrb_exec_recursive_paired(mrb, recursive_equal, s, s2, (void*)0);
-}
-
-static mrb_value
-recursive_eql(mrb_state *mrb, mrb_value s, mrb_value s2, int recur)
-{
- mrb_value *ptr, *ptr2;
- long i, len;
-
- if (recur) return mrb_true_value(); /* Subtle! */
- ptr = RSTRUCT_PTR(s);
- ptr2 = RSTRUCT_PTR(s2);
- len = RSTRUCT_LEN(s);
- for (i=0; i<len; i++) {
- if (!mrb_eql(mrb, ptr[i], ptr2[i])) return mrb_false_value();
- }
- return mrb_true_value();
+ ptr = RSTRUCT_PTR(s);
+ ptr2 = RSTRUCT_PTR(s2);
+ len = RSTRUCT_LEN(s);
+ for (i=0; i<len; i++) {
+ if (!mrb_equal(mrb, ptr[i], ptr2[i])) return mrb_false_value();
+ }
+ return mrb_true_value();
}
/* 15.2.18.4.12(x) */
@@ -766,6 +737,8 @@ static mrb_value
mrb_struct_eql(mrb_state *mrb, mrb_value s)
{
mrb_value s2;
+ mrb_value *ptr, *ptr2;
+ long i, len;
mrb_get_args(mrb, "o", &s2);
if (mrb_obj_equal(mrb, s, s2)) return mrb_true_value();
@@ -775,7 +748,13 @@ mrb_struct_eql(mrb_state *mrb, mrb_value s)
mrb_bug("inconsistent struct"); /* should never happen */
}
- return mrb_exec_recursive_paired(mrb, recursive_eql, s, s2, (void*)0);
+ ptr = RSTRUCT_PTR(s);
+ ptr2 = RSTRUCT_PTR(s2);
+ len = RSTRUCT_LEN(s);
+ for (i=0; i<len; i++) {
+ if (!mrb_eql(mrb, ptr[i], ptr2[i])) return mrb_false_value();
+ }
+ return mrb_true_value();
}
/*

0 comments on commit 80c8908

Please sign in to comment.
Something went wrong with that request. Please try again.