Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[not bug] range check optimization #348

Closed
monaka opened this Issue · 0 comments

2 participants

@monaka

This is not bug.
I think compares in range.c is well-behaved but slightly redundant.
How about optimize like this?

diff --git a/src/range.c b/src/range.c
index 859bb27..34ca79a 100644
--- a/src/range.c
+++ b/src/range.c
@@ -185,14 +185,14 @@ mrb_range_eq(mrb_state *mrb, mrb_value range)
 static int
 r_le(mrb_state *mrb, mrb_value a, mrb_value b)
 {
-  //int c;
   mrb_value r = mrb_funcall(mrb, a, "<=>", 1, b); /* compare result */
   /* output :a < b => -1, a = b =>  0, a > b => +1 */

-  if (mrb_nil_p(r)) return FALSE;
+  if (mrb_type(r) == MRB_TT_FIXNUM) {
+    int c = mrb_fixnum(r);
+    if (c == 0 || c == -1) return TRUE;
+  }

-  if (mrb_obj_equal(mrb, r, mrb_fixnum_value(0))) return TRUE;
-  if (mrb_obj_equal(mrb, r, mrb_fixnum_value(-1))) return TRUE;
   return FALSE;
 }

@matz matz closed this in 84ec555
@monaka monaka referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@monaka monaka referenced this issue from a commit in monaka/mruby
@monaka monaka Range optimization. similar to #348 e896c1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.