Skip to content

Commit

Permalink
Replace global Hash usage with TS::Cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkone committed Sep 30, 2013
1 parent bd6adc8 commit 5630bbc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 2 additions & 0 deletions Rakefile
Expand Up @@ -17,4 +17,6 @@ Hoe.spec 'arel' do
self.licenses = ['MIT']
self.readme_file = 'README.markdown'
self.extra_rdoc_files = FileList['README.markdown']

dependency('thread_safe', '~> 0.1')
end
5 changes: 3 additions & 2 deletions lib/arel/visitors/to_sql.rb
@@ -1,5 +1,6 @@
require 'bigdecimal'
require 'date'
require 'thread_safe'

module Arel
module Visitors
Expand Down Expand Up @@ -56,8 +57,8 @@ class ToSql < Arel::Visitors::Visitor
def initialize connection
@connection = connection
@schema_cache = connection.schema_cache
@quoted_tables = {}
@quoted_columns = {}
@quoted_tables = ThreadSafe::Cache.new
@quoted_columns = ThreadSafe::Cache.new
end

private
Expand Down
8 changes: 5 additions & 3 deletions lib/arel/visitors/visitor.rb
@@ -1,3 +1,5 @@
require 'thread_safe'

module Arel
module Visitors
class Visitor
Expand All @@ -7,10 +9,10 @@ def accept object

private

DISPATCH = Hash.new do |hash, visitor_class|
DISPATCH = ThreadSafe::Cache.new do |hash, visitor_class|
hash[visitor_class] =
Hash.new do |hash, node_class|
hash[node_class] = "visit_#{(node_class.name || '').gsub('::', '_')}"
ThreadSafe::Cache.new(:initial_capacity => 2) do |inner_hash, node_class|
inner_hash[node_class] = "visit_#{(node_class.name || '').gsub('::', '_')}"
end
end

Expand Down

0 comments on commit 5630bbc

Please sign in to comment.