From 3efb57b140db9b9c2a9e01fa16cf2a0d3f48b098 Mon Sep 17 00:00:00 2001 From: Damian Janowski Date: Tue, 18 Dec 2012 14:24:54 -0300 Subject: [PATCH] Make `TimedQueue` use `pop`/`push` for better performance. --- lib/timed_queue.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/timed_queue.rb b/lib/timed_queue.rb index fa9031d..ce435ef 100644 --- a/lib/timed_queue.rb +++ b/lib/timed_queue.rb @@ -10,7 +10,7 @@ class TimedQueue def push(obj) @mutex.synchronize do - @que.unshift obj + @que.push obj @resource.broadcast end end @@ -20,7 +20,7 @@ class TimedQueue deadline = Time.now + timeout @mutex.synchronize do loop do - return @que.shift unless @que.empty? + return @que.pop unless @que.empty? to_wait = deadline - Time.now raise Timeout::Error, "Waited #{timeout} sec" if to_wait <= 0 @resource.wait(@mutex, to_wait)