From 6ddbd1844a6fd6aca2992f5f75c9f605cf89808f Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Sun, 8 Apr 2012 22:30:18 -0300 Subject: [PATCH] Inline the symbolize_keys/stringify_keys methods user system total real symbolize_keys 5.980000 0.070000 6.050000 ( 6.048187) new_symbolize_keys 4.310000 0.050000 4.360000 ( 4.364745) --- .../lib/active_support/core_ext/hash/keys.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/hash/keys.rb b/activesupport/lib/active_support/core_ext/hash/keys.rb index da7c3dfbe8..65c3736593 100644 --- a/activesupport/lib/active_support/core_ext/hash/keys.rb +++ b/activesupport/lib/active_support/core_ext/hash/keys.rb @@ -1,7 +1,11 @@ class Hash # Return a new hash with all keys converted to strings. def stringify_keys - dup.stringify_keys! + result = {} + keys.each do |key| + result[key.to_s] = self[key] + end + result end # Destructively convert all keys to strings. @@ -15,7 +19,11 @@ class Hash # Return a new hash with all keys converted to symbols, as long as # they respond to +to_sym+. def symbolize_keys - dup.symbolize_keys! + result = {} + keys.each do |key| + result[(key.to_sym rescue key)] = self[key] + end + result end # Destructively convert all keys to symbols, as long as they respond