Permalink
Browse files

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
  • Loading branch information...
1 parent 66fc1d6 commit bbef7b012f8ef3ce9c92c553379a63814201e12f @seamusabshere seamusabshere committed Feb 2, 2012
Showing with 1 addition and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/connection_adapters/abstract_mysql_adapter.rb
@@ -505,7 +505,7 @@ def pk_and_sequence_for(table)
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

0 comments on commit bbef7b0

Please sign in to comment.