diff options
author | Seamus Abshere <seamus@abshere.net> | 2012-02-01 18:58:00 -0600 |
---|---|---|
committer | Seamus Abshere <seamus@abshere.net> | 2012-02-01 18:58:00 -0600 |
commit | bbef7b012f8ef3ce9c92c553379a63814201e12f (patch) | |
tree | b71da8f0ebcb5eeba189d78c7e6adcf545fe9185 /activerecord/lib/active_record/connection_adapters | |
parent | 66fc1d6ac8f0f7b797ae18fdcb15cd618e4251f1 (diff) | |
download | rails-bbef7b012f8ef3ce9c92c553379a63814201e12f.tar.gz rails-bbef7b012f8ef3ce9c92c553379a63814201e12f.tar.bz2 rails-bbef7b012f8ef3ce9c92c553379a63814201e12f.zip |
Possibly clearer way of getting rid of ` and "
Incidentally it's also faster...
>> a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.tr('`"', "") } }
=> 0.7388770580291748
>> a = 'hello "id` world'; Benchmark.realtime { 500_000.times { a.gsub(/[`"]/, "") } }
=> 1.7843739986419678
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb index 9d9dbcc355..9fc5973635 100644 --- a/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb @@ -505,7 +505,7 @@ module ActiveRecord execute_and_free("SHOW CREATE TABLE #{quote_table_name(table)}", 'SCHEMA') do |result| create_table = each_hash(result).first[:"Create Table"] if create_table.to_s =~ /PRIMARY KEY\s+\((.+)\)/ - keys = $1.split(",").map { |key| key.gsub(/[`"]/, "") } + keys = $1.split(",").map { |key| key.tr('`"', "") } keys.length == 1 ? [keys.first, nil] : nil else nil |