Skip to content
Browse files

Use a hash to look up column definitions

  • Loading branch information...
1 parent 7e176a6 commit 76c29a64b940ca82c7a15de5598f5340046b9cca @tenderlove tenderlove committed Dec 7, 2011
View
5 activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb
@@ -66,6 +66,7 @@ class TableDefinition
def initialize(base)
@columns = []
+ @columns_hash = {}
@base = base
end
@@ -86,8 +87,7 @@ def primary_key(name)
# Returns a ColumnDefinition for the column with name +name+.
def [](name)
- name = name.to_s
- @columns.find { |column| column.name == name }
+ @columns_hash[name.to_s]
end
# Instantiates a new column for the table.
@@ -283,6 +283,7 @@ def to_sql
def new_column_definition(base, name, type)
definition = ColumnDefinition.new base, name, type
@columns << definition
+ @columns_hash[name] = definition
definition
end

2 comments on commit 76c29a6

@jonleighton
Ruby on Rails member

@tenderlove somewhere around this commit the build starts failing spectacularly on 1.8

@tenderlove
Ruby on Rails member

SWEET. I'll take a look

Please sign in to comment.
Something went wrong with that request. Please try again.