summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2008-01-26 17:21:54 +0000
committerJamis Buck <jamis@37signals.com>2008-01-26 17:21:54 +0000
commit03e32bf5a3d191361315a1e57ebf762e5b15b8c9 (patch)
tree69c85fb373bca4a6c527dd1c03490c069e111811 /lib
parent5af64dbc3ecf75aec1cfb53f92b1193112be6cc5 (diff)
downloadthird_party-sqlite3-ruby-03e32bf5a3d191361315a1e57ebf762e5b15b8c9.tar.gz
third_party-sqlite3-ruby-03e32bf5a3d191361315a1e57ebf762e5b15b8c9.tar.xz
third_party-sqlite3-ruby-03e32bf5a3d191361315a1e57ebf762e5b15b8c9.zip
cache the type-name, instead of recomputing it on each request (thanks Erik Veenstra)
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlite3/translator.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/sqlite3/translator.rb b/lib/sqlite3/translator.rb
index 14d28b6..31430b2 100644
--- a/lib/sqlite3/translator.rb
+++ b/lib/sqlite3/translator.rb
@@ -48,6 +48,7 @@ module SQLite3
# translators for most SQL data types.
def initialize
@translators = Hash.new( proc { |type,value| value } )
+ @type_name_cache = {}
register_default_translators
end
@@ -81,9 +82,11 @@ module SQLite3
# A convenience method for working with type names. This returns the "base"
# type name, without any parenthetical data.
def type_name( type )
- return "" if type.nil?
- type = $1 if type =~ /^(.*?)\(/
- type.upcase
+ @type_name_cache[type] ||= begin
+ type = "" if type.nil?
+ type = $1 if type =~ /^(.*?)\(/
+ type.upcase
+ end
end
private :type_name