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

ruby-changes:42075

From: mame <ko1@a...>
Date: Thu, 17 Mar 2016 21:03:54 +0900 (JST)
Subject: [ruby-changes:42075] mame:r54149 (trunk): * internal.c: struct cmp_opt_data added for refactoring out a data

mame	2016-03-17 21:03:48 +0900 (Thu, 17 Mar 2016)

  New Revision: 54149

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

  Log:
    * internal.c: struct cmp_opt_data added for refactoring out a data
      structure for CMP_OPTIMIZABLE
    
    * array.c (struct ary_sort_data): use struct cmp_opt_data.
    
    * enum.c (struct min_t, max_t, min_max_t): use struct cmp_opt_data.

  Modified files:
    trunk/ChangeLog
    trunk/array.c
    trunk/enum.c
    trunk/internal.h
Index: enum.c
===================================================================
--- enum.c	(revision 54148)
+++ enum.c	(revision 54149)
@@ -1495,8 +1495,7 @@ enum_none(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enum.c#L1495
 
 struct min_t {
     VALUE min;
-    int opt_methods;
-    int opt_inited;
+    struct cmp_opt_data cmp_opt;
 };
 
 static VALUE
@@ -1510,7 +1509,7 @@ min_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args https://github.com/ruby/ruby/blob/trunk/enum.c#L1509
 	memo->min = i;
     }
     else {
-	if (OPTIMIZED_CMP(i, memo->min, memo) < 0) {
+	if (OPTIMIZED_CMP(i, memo->min, memo->cmp_opt) < 0) {
 	    memo->min = i;
 	}
     }
@@ -1575,8 +1574,8 @@ enum_min(int argc, VALUE *argv, VALUE ob https://github.com/ruby/ruby/blob/trunk/enum.c#L1574
        return nmin_run(obj, num, 0, 0);
 
     m->min = Qundef;
-    m->opt_methods = 0;
-    m->opt_inited = 0;
+    m->cmp_opt.opt_methods = 0;
+    m->cmp_opt.opt_inited = 0;
     if (rb_block_given_p()) {
 	rb_block_call(obj, id_each, 0, 0, min_ii, memo);
     }
@@ -1590,8 +1589,7 @@ enum_min(int argc, VALUE *argv, VALUE ob https://github.com/ruby/ruby/blob/trunk/enum.c#L1589
 
 struct max_t {
     VALUE max;
-    int opt_methods;
-    int opt_inited;
+    struct cmp_opt_data cmp_opt;
 };
 
 static VALUE
@@ -1605,7 +1603,7 @@ max_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, args https://github.com/ruby/ruby/blob/trunk/enum.c#L1603
 	memo->max = i;
     }
     else {
-	if (OPTIMIZED_CMP(i, memo->max, memo) > 0) {
+	if (OPTIMIZED_CMP(i, memo->max, memo->cmp_opt) > 0) {
 	    memo->max = i;
 	}
     }
@@ -1669,8 +1667,8 @@ enum_max(int argc, VALUE *argv, VALUE ob https://github.com/ruby/ruby/blob/trunk/enum.c#L1667
        return nmin_run(obj, num, 0, 1);
 
     m->max = Qundef;
-    m->opt_methods = 0;
-    m->opt_inited = 0;
+    m->cmp_opt.opt_methods = 0;
+    m->cmp_opt.opt_inited = 0;
     if (rb_block_given_p()) {
 	rb_block_call(obj, id_each, 0, 0, max_ii, (VALUE)memo);
     }
@@ -1686,8 +1684,7 @@ struct minmax_t { https://github.com/ruby/ruby/blob/trunk/enum.c#L1684
     VALUE min;
     VALUE max;
     VALUE last;
-    int opt_methods;
-    int opt_inited;
+    struct cmp_opt_data cmp_opt;
 };
 
 static void
@@ -1700,11 +1697,11 @@ minmax_i_update(VALUE i, VALUE j, struct https://github.com/ruby/ruby/blob/trunk/enum.c#L1697
 	memo->max = j;
     }
     else {
-	n = OPTIMIZED_CMP(i, memo->min, memo);
+	n = OPTIMIZED_CMP(i, memo->min, memo->cmp_opt);
 	if (n < 0) {
 	    memo->min = i;
 	}
-	n = OPTIMIZED_CMP(j, memo->max, memo);
+	n = OPTIMIZED_CMP(j, memo->max, memo->cmp_opt);
 	if (n > 0) {
 	    memo->max = j;
 	}
@@ -1727,7 +1724,7 @@ minmax_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, _ https://github.com/ruby/ruby/blob/trunk/enum.c#L1724
     j = memo->last;
     memo->last = Qundef;
 
-    n = OPTIMIZED_CMP(j, i, memo);
+    n = OPTIMIZED_CMP(j, i, memo->cmp_opt);
     if (n == 0)
         i = j;
     else if (n < 0) {
@@ -1817,8 +1814,8 @@ enum_minmax(VALUE obj) https://github.com/ruby/ruby/blob/trunk/enum.c#L1814
 
     m->min = Qundef;
     m->last = Qundef;
-    m->opt_methods = 0;
-    m->opt_inited = 0;
+    m->cmp_opt.opt_methods = 0;
+    m->cmp_opt.opt_inited = 0;
     if (rb_block_given_p()) {
 	rb_block_call(obj, id_each, 0, 0, minmax_ii, memo);
 	if (m->last != Qundef)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 54148)
+++ ChangeLog	(revision 54149)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Mar 17 21:02:42 2016  Yusuke Endoh  <mame@t...>
+
+	* internal.c: struct cmp_opt_data added for refactoring out a data
+	  structure for CMP_OPTIMIZABLE
+
+	* array.c (struct ary_sort_data): use struct cmp_opt_data.
+
+	* enum.c (struct min_t, max_t, min_max_t): use struct cmp_opt_data.
+
 Thu Mar 17 20:55:21 2016  Tanaka Akira  <akr@f...>
 
 	* enum.c (ary_inject_op): Extracted from enum_inject.
Index: array.c
===================================================================
--- array.c	(revision 54148)
+++ array.c	(revision 54149)
@@ -2364,8 +2364,7 @@ rb_ary_rotate_m(int argc, VALUE *argv, V https://github.com/ruby/ruby/blob/trunk/array.c#L2364
 
 struct ary_sort_data {
     VALUE ary;
-    int opt_methods;
-    int opt_inited;
+    struct cmp_opt_data cmp_opt;
 };
 
 static VALUE
@@ -2399,12 +2398,12 @@ sort_2(const void *ap, const void *bp, v https://github.com/ruby/ruby/blob/trunk/array.c#L2398
     VALUE a = *(const VALUE *)ap, b = *(const VALUE *)bp;
     int n;
 
-    if (FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data, Fixnum)) {
+    if (FIXNUM_P(a) && FIXNUM_P(b) && CMP_OPTIMIZABLE(data->cmp_opt, Fixnum)) {
 	if ((long)a > (long)b) return 1;
 	if ((long)a < (long)b) return -1;
 	return 0;
     }
-    if (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data, String)) {
+    if (STRING_P(a) && STRING_P(b) && CMP_OPTIMIZABLE(data->cmp_opt, String)) {
 	return rb_str_cmp(a, b);
     }
 
@@ -2448,8 +2447,8 @@ rb_ary_sort_bang(VALUE ary) https://github.com/ruby/ruby/blob/trunk/array.c#L2447
 
 	RBASIC_CLEAR_CLASS(tmp);
 	data.ary = tmp;
-	data.opt_methods = 0;
-	data.opt_inited = 0;
+	data.cmp_opt.opt_methods = 0;
+	data.cmp_opt.opt_inited = 0;
 	RARRAY_PTR_USE(tmp, ptr, {
 	    ruby_qsort(ptr, len, sizeof(VALUE),
 		       rb_block_given_p()?sort_1:sort_2, &data);
Index: internal.h
===================================================================
--- internal.h	(revision 54148)
+++ internal.h	(revision 54149)
@@ -685,13 +685,18 @@ enum { https://github.com/ruby/ruby/blob/trunk/internal.h#L685
     cmp_optimizable_count
 };
 
+struct cmp_opt_data {
+    int opt_methods;
+    int opt_inited;
+};
+
 #define CMP_OPTIMIZABLE_BIT(type) (1U << TOKEN_PASTE(cmp_opt_,type))
 #define CMP_OPTIMIZABLE(data, type) \
-    (((data)->opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
-     ((data)->opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
-     (((data)->opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
+    (((data).opt_inited & CMP_OPTIMIZABLE_BIT(type)) ? \
+     ((data).opt_methods & CMP_OPTIMIZABLE_BIT(type)) : \
+     (((data).opt_inited |= CMP_OPTIMIZABLE_BIT(type)), \
       rb_method_basic_definition_p(TOKEN_PASTE(rb_c,type), id_cmp) && \
-      ((data)->opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
+      ((data).opt_methods |= CMP_OPTIMIZABLE_BIT(type))))
 
 /* ment is in method.h */
 

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

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