summaryrefslogtreecommitdiff
path: root/ext/thread
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-07 16:36:16 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-11-07 16:36:16 +0000
commit13d241489a77634a83de04ec90b9bd5983a0493f (patch)
tree2bad996a354cd12f950f211a953bc1473dbe7809 /ext/thread
parent72ce1a4759b853b02eab31786acbb69ba80b4fd8 (diff)
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
Diffstat (limited to 'ext/thread')
-rw-r--r--ext/thread/thread.c9
1 files 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);
}