Replace Hash#keys.each with Hash#each_key for some perf boost

This commit is contained in:
Tan Le
2015-04-18 21:53:53 +10:00
parent d16df04c76
commit 9fbc763902
12 changed files with 15 additions and 15 deletions

View File

@@ -300,7 +300,7 @@ class PostRevisor
return unless revision = PostRevision.find_by(post_id: @post.id, number: @post.version)
revision.user_id = @post.last_editor_id
modifications = post_changes.merge(@topic_changes.diff)
modifications.keys.each do |field|
modifications.each_key do |field|
if revision.modifications.has_key?(field)
old_value = revision.modifications[field][0]
new_value = modifications[field][1]

View File

@@ -33,7 +33,7 @@ class ScoreCalculator
def update_posts_score(min_topic_age)
components = []
@weightings.keys.each { |k| components << "COALESCE(#{k}, 0) * :#{k}" }
@weightings.each_key { |k| components << "COALESCE(#{k}, 0) * :#{k}" }
components = components.join(" + ")
builder = SqlBuilder.new(

View File

@@ -16,7 +16,7 @@ class SiteSettings::YamlLoader
def load
yaml = YAML.load_file(@file)
yaml.keys.each do |category|
yaml.each_key do |category|
yaml[category].each do |setting_name, hash|
if hash.is_a?(Hash)
# Get default value for the site setting: