lib/picky/pool.rb in picky-4.6.1 vs lib/picky/pool.rb in picky-4.6.2
- old
+ new
@@ -5,16 +5,34 @@
#
module Pool
class << self
+ # Installs itself on a few internal classes.
+ #
+ # Note: If you need to run two consecutive queries,
+ # this can't be used.
+ #
+ # TODO Also install calling release_all after each query.
+ #
+ def install
+ Query::Token.extend self
+ Query::Tokens.extend self
+ Query::Combination.extend self
+ Query::Combinations.extend self
+ Query::Allocation.extend self
+ Query::Allocations.extend self
+ end
+
+ # Initialise/Reset the pool.
+ #
def clear
require 'set'
@pools = Set.new
end
- # Add a Pool to the managed pools.
+ # Add a pooled class to the managed pools.
#
def add klass
@pools << klass
end
@@ -32,20 +50,21 @@
def self.extended klass
add klass
class << klass
+
+ # Initialise/Reset the class pool.
#
- #
def clear
@__free__ = []
@__used__ = []
end
# Obtain creates a new reference if there is no free one
# and uses an existing one if there is.
#
- def obtain *args, &block
+ def new *args, &block
unless reference = @__free__.shift
reference = allocate
end
reference.send :initialize, *args, &block
@__used__ << reference
\ No newline at end of file