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

ruby-changes:36234

From: nobu <ko1@a...>
Date: Sat, 8 Nov 2014 01:36:29 +0900 (JST)
Subject: [ruby-changes:36234] nobu:r48315 (trunk): thread.c: no function callsin RARRAY_LEN

nobu	2014-11-08 01:36:16 +0900 (Sat, 08 Nov 2014)

  New Revision: 48315

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

  Log:
    thread.c: no function callsin RARRAY_LEN
    
    * ext/thread/thread.c (queue_length, queue_num_waiting): avoid
      function calls in RARRAY_LEN macro which evaluates the argument
      multiple times.
    
    * ext/thread/thread.c (rb_szqueue_num_waiting): ditto.

  Modified files:
    trunk/ext/thread/thread.c
Index: ext/thread/thread.c
===================================================================
--- ext/thread/thread.c	(revision 48314)
+++ ext/thread/thread.c	(revision 48315)
@@ -243,13 +243,15 @@ rb_queue_push(VALUE self, VALUE obj) https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L243
 static unsigned long
 queue_length(VALUE self)
 {
-    return RARRAY_LEN(GET_QUEUE_QUE(self));
+    VALUE que = GET_QUEUE_QUE(self);
+    return RARRAY_LEN(que);
 }
 
 static unsigned long
 queue_num_waiting(VALUE self)
 {
-    return RARRAY_LEN(GET_QUEUE_WAITERS(self));
+    VALUE waiters = GET_QUEUE_WAITERS(self);
+    return RARRAY_LEN(waiters);
 }
 
 struct waiting_delete {
@@ -548,7 +550,8 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/thread/thread.c#L550
 rb_szqueue_num_waiting(VALUE self)
 {
     long len = queue_num_waiting(self);
-    len += RARRAY_LEN(GET_SZQUEUE_WAITERS(self));
+    VALUE waiters = GET_SZQUEUE_WAITERS(self);
+    len += RARRAY_LEN(waiters);
     return ULONG2NUM(len);
 }
 

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

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