From 13d241489a77634a83de04ec90b9bd5983a0493f Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 7 Nov 2014 16:36:16 +0000 Subject: [PATCH] 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48315 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/thread/thread.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ext/thread/thread.c b/ext/thread/thread.c index c14443b06c..b8656a1d97 100644 --- a/ext/thread/thread.c +++ b/ext/thread/thread.c @@ -243,13 +243,15 @@ rb_queue_push(VALUE self, VALUE obj) 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 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); }