From e3cb08c172842dd7935021041013eb51b7b7d79a Mon Sep 17 00:00:00 2001 From: Damian Janowski Date: Wed, 14 Mar 2012 10:24:47 -0300 Subject: [PATCH] Cache options to instance variables for faster access. Also lets the hash be GC'd. --- lib/connection_pool.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/connection_pool.rb b/lib/connection_pool.rb index 259e4c2..1554533 100644 --- a/lib/connection_pool.rb +++ b/lib/connection_pool.rb @@ -34,8 +34,12 @@ class ConnectionPool def initialize(options={}, &block) raise ArgumentError, 'Connection pool requires a block' unless block - @options = DEFAULTS.merge(options) - @available = ::TimedQueue.new(options[:size], &block) + options = DEFAULTS.merge(options) + + @size = options[:size] || DEFAULTS[:size] + @timeout = options[:timeout] || DEFAULTS + + @available = ::TimedQueue.new(@size, &block) @oid = @available.object_id end @@ -50,7 +54,7 @@ class ConnectionPool def checkout ::Thread.current[:"current-#{@oid}"] ||= begin - @available.timed_pop(@options[:timeout]) + @available.timed_pop(@timeout) end end