Permalink
Browse files

Improve the method

* cache `o.name` value
* Avoid extra `concat` call
* Avoid extra `<<` call
  • Loading branch information...
1 parent fb74394 commit 4e2ca9b23fcaa98f4ef375a3a6d8eee579baec94 @rafaelfranca rafaelfranca committed Mar 26, 2014
Showing with 6 additions and 5 deletions.
  1. +6 −5 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -7,11 +7,12 @@ class AbstractMysqlAdapter < AbstractAdapter
class SchemaCreation < AbstractAdapter::SchemaCreation
def visit_TableDefinition(o)
- create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE "
- create_sql << "#{quote_table_name(o.name)} "
- statements = []
- statements.concat(o.columns.map { |c| accept c })
- statements.concat(o.indexes.map { |(column_name, options)| index_in_create(o.name, column_name, options) })
+ name = o.name
+ create_sql = "CREATE#{' TEMPORARY' if o.temporary} TABLE #{quote_table_name(name)} "
+
+ statements = o.columns.map { |c| accept c }
+ statements.concat(o.indexes.map { |column_name, options| index_in_create(name, column_name, options) })
+
create_sql << "(#{statements.join(', ')}) " if statements.present?
create_sql << "#{o.options}"
create_sql << " AS #{@conn.to_sql(o.as)}" if o.as

0 comments on commit 4e2ca9b

Please sign in to comment.