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

ruby-changes:46194

From: normal <ko1@a...>
Date: Tue, 11 Apr 2017 03:17:04 +0900 (JST)
Subject: [ruby-changes:46194] normal:r58309 (trunk): time.c: use predefined IDs

normal	2017-04-11 03:16:58 +0900 (Tue, 11 Apr 2017)

  New Revision: 58309

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

  Log:
    time.c: use predefined IDs
    
    This reduces rb_intern calls during startup and shortens code.
    
    * time.c: include id.h for predefined IDs
      (id_mul, id_eq, id_ne, id_cmp): remove static variables
      (eq): replace id_eq with idEq
      (cmp, wcmp): replace id_cmp with idCmp
      (weq): replace id_eq with idEq
      (time_timespec): replace id_mul with '*'
      (Init_Time): remove rb_intern calls for removed variables
    * common.mk (time.$(OBJEXT)): add depend on id.h

  Modified files:
    trunk/common.mk
    trunk/time.c
Index: time.c
===================================================================
--- time.c	(revision 58308)
+++ time.c	(revision 58309)
@@ -32,9 +32,10 @@ https://github.com/ruby/ruby/blob/trunk/time.c#L32
 #endif
 
 #include "timev.h"
+#include "id.h"
 
-static ID id_divmod, id_mul, id_submicro, id_nano_num, id_nano_den, id_offset, id_zone;
-static ID id_eq, id_ne, id_quo, id_div, id_cmp;
+static ID id_divmod, id_submicro, id_nano_num, id_nano_den, id_offset, id_zone;
+static ID id_quo, id_div;
 
 #define NDIV(x,y) (-(-((x)+1)/(y))-1)
 #define NMOD(x,y) ((y)-(-((x)+1)%(y))-1)
@@ -50,7 +51,7 @@ eq(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/time.c#L51
     if (FIXNUM_P(x) && FIXNUM_P(y)) {
         return x == y;
     }
-    return RTEST(rb_funcall(x, id_eq, 1, y));
+    return RTEST(rb_funcall(x, idEq, 1, y));
 }
 
 static int
@@ -63,7 +64,7 @@ cmp(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/time.c#L64
             return 1;
         return 0;
     }
-    return rb_cmpint(rb_funcall(x, id_cmp, 1, y), x, y);
+    return rb_cmpint(rb_funcall(x, idCmp, 1, y), x, y);
 }
 
 #define ne(x,y) (!eq((x),(y)))
@@ -308,7 +309,7 @@ weq(wideval_t wx, wideval_t wy) https://github.com/ruby/ruby/blob/trunk/time.c#L309
     if (FIXWV_P(wx) && FIXWV_P(wy)) {
         return WIDEVAL_GET(wx) == WIDEVAL_GET(wy);
     }
-    return RTEST(rb_funcall(w2v(wx), id_eq, 1, w2v(wy)));
+    return RTEST(rb_funcall(w2v(wx), idEq, 1, w2v(wy)));
 #else
     return eq(WIDEVAL_GET(wx), WIDEVAL_GET(wy));
 #endif
@@ -332,7 +333,7 @@ wcmp(wideval_t wx, wideval_t wy) https://github.com/ruby/ruby/blob/trunk/time.c#L333
 #endif
     x = w2v(wx);
     y = w2v(wy);
-    return rb_cmpint(rb_funcall(x, id_cmp, 1, y), x, y);
+    return rb_cmpint(rb_funcall(x, idCmp, 1, y), x, y);
 }
 
 #define wne(x,y) (!weq((x),(y)))
@@ -2268,7 +2269,7 @@ time_timespec(VALUE num, int interval) https://github.com/ruby/ruby/blob/trunk/time.c#L2269
             t.tv_sec = NUM2TIMET(i);
             if (interval && t.tv_sec < 0)
                 rb_raise(rb_eArgError, "%s must be positive", tstr);
-            f = rb_funcall(f, id_mul, 1, INT2FIX(1000000000));
+            f = rb_funcall(f, '*', 1, INT2FIX(1000000000));
             t.tv_nsec = NUM2LONG(f);
         }
         else {
@@ -4796,13 +4797,9 @@ Init_Time(void) https://github.com/ruby/ruby/blob/trunk/time.c#L4797
 #undef rb_intern
 #define rb_intern(str) rb_intern_const(str)
 
-    id_eq = rb_intern("==");
-    id_ne = rb_intern("!=");
     id_quo = rb_intern("quo");
     id_div = rb_intern("div");
-    id_cmp = rb_intern("<=>");
     id_divmod = rb_intern("divmod");
-    id_mul = rb_intern("*");
     id_submicro = rb_intern("submicro");
     id_nano_num = rb_intern("nano_num");
     id_nano_den = rb_intern("nano_den");
Index: common.mk
===================================================================
--- common.mk	(revision 58308)
+++ common.mk	(revision 58309)
@@ -2608,6 +2608,7 @@ time.$(OBJEXT): $(top_srcdir)/include/ru https://github.com/ruby/ruby/blob/trunk/common.mk#L2608
 time.$(OBJEXT): {$(VPATH)}config.h
 time.$(OBJEXT): {$(VPATH)}defines.h
 time.$(OBJEXT): {$(VPATH)}encoding.h
+time.$(OBJEXT): {$(VPATH)}id.h
 time.$(OBJEXT): {$(VPATH)}intern.h
 time.$(OBJEXT): {$(VPATH)}internal.h
 time.$(OBJEXT): {$(VPATH)}io.h

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

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