Commit 23f65aa9 authored by maeda's avatar maeda

Replace Enumerable#sort with faster Enumerable#sort_by (#29299).

Patch by Go MAEDA.


git-svn-id: https://svn.redmine.org/redmine/trunk@17462 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 189bf36a
...@@ -46,7 +46,7 @@ class SettingsController < ApplicationController ...@@ -46,7 +46,7 @@ class SettingsController < ApplicationController
end end
@options = {} @options = {}
user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort{|a, b| a[1] <=> b[1]} user_format = User::USER_FORMATS.collect{|key, value| [key, value[:setting_order]]}.sort_by{|f| f[1]}
@options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]} @options[:user_format] = user_format.collect{|f| [User.current.name(f[0]), f[0].to_s]}
@deliveries = ActionMailer::Base.perform_deliveries @deliveries = ActionMailer::Base.perform_deliveries
......
...@@ -21,9 +21,9 @@ module ActivitiesHelper ...@@ -21,9 +21,9 @@ module ActivitiesHelper
def sort_activity_events(events) def sort_activity_events(events)
events_by_group = events.group_by(&:event_group) events_by_group = events.group_by(&:event_group)
sorted_events = [] sorted_events = []
events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each do |event| events.sort_by(&:event_datetime).reverse_each do |event|
if group_events = events_by_group.delete(event.event_group) if group_events = events_by_group.delete(event.event_group)
group_events.sort {|x, y| y.event_datetime <=> x.event_datetime}.each_with_index do |e, i| group_events.sort_by(&:event_datetime).reverse.each_with_index do |e, i|
sorted_events << [e, i > 0] sorted_events << [e, i > 0]
end end
end end
......
...@@ -20,6 +20,6 @@ ...@@ -20,6 +20,6 @@
module IssueRelationsHelper module IssueRelationsHelper
def collection_for_relation_type_select def collection_for_relation_type_select
values = IssueRelation::TYPES values = IssueRelation::TYPES
values.keys.sort{|x,y| values[x][:order] <=> values[y][:order]}.collect{|k| [l(values[k][:name]), k]} values.keys.sort_by{|k| values[k][:order]}.collect{|k| [l(values[k][:name]), k]}
end end
end end
...@@ -269,7 +269,7 @@ module RepositoriesHelper ...@@ -269,7 +269,7 @@ module RepositoriesHelper
:href => block_given? ? yield(commit.scmid) : commit.scmid :href => block_given? ? yield(commit.scmid) : commit.scmid
} }
end end
heads.sort! { |head1, head2| head1.to_s <=> head2.to_s } heads.sort_by!(&:to_s)
space = nil space = nil
heads.each do |head| heads.each do |head|
if commits_by_scmid.include? head.scmid if commits_by_scmid.include? head.scmid
......
...@@ -55,7 +55,7 @@ module SearchHelper ...@@ -55,7 +55,7 @@ module SearchHelper
def render_results_by_type(results_by_type) def render_results_by_type(results_by_type)
links = [] links = []
# Sorts types by results count # Sorts types by results count
results_by_type.keys.sort {|a, b| results_by_type[b] <=> results_by_type[a]}.each do |t| results_by_type.keys.sort_by {|k| results_by_type[k]}.reverse_each do |t|
c = results_by_type[t] c = results_by_type[t]
next if c == 0 next if c == 0
text = "#{type_label(t)} (#{c})" text = "#{type_label(t)} (#{c})"
......
...@@ -118,7 +118,7 @@ class QueryCustomFieldColumn < QueryColumn ...@@ -118,7 +118,7 @@ class QueryCustomFieldColumn < QueryColumn
def value_object(object) def value_object(object)
if custom_field.visible_by?(object.project, User.current) if custom_field.visible_by?(object.project, User.current)
cv = object.custom_values.select {|v| v.custom_field_id == @cf.id} cv = object.custom_values.select {|v| v.custom_field_id == @cf.id}
cv.size > 1 ? cv.sort {|a,b| a.value.to_s <=> b.value.to_s} : cv.first cv.size > 1 ? cv.sort_by {|e| e.value.to_s} : cv.first
else else
nil nil
end end
......
...@@ -619,7 +619,7 @@ module Redmine ...@@ -619,7 +619,7 @@ module Redmine
end end
def self.sort_issues!(issues) def self.sort_issues!(issues)
issues.sort! {|a, b| sort_issue_logic(a) <=> sort_issue_logic(b)} issues.sort_by! {|issue| sort_issue_logic(issue)}
end end
def self.sort_issue_logic(issue) def self.sort_issue_logic(issue)
......
...@@ -120,7 +120,7 @@ module Redmine ...@@ -120,7 +120,7 @@ module Redmine
valid_languages. valid_languages.
select {|locale| ::I18n.exists?(:general_lang_name, locale)}. select {|locale| ::I18n.exists?(:general_lang_name, locale)}.
map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}. map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.
sort {|x,y| x.first <=> y.first } sort_by(&:first)
else else
ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do
languages_options :cache => false languages_options :cache => false
......
...@@ -206,7 +206,7 @@ module Redmine ...@@ -206,7 +206,7 @@ module Redmine
:path => with_leading_slash(p), :path => with_leading_slash(p),
:from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil), :from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : nil),
:from_revision => (cpmap.member?(p) ? le['node'] : nil)} :from_revision => (cpmap.member?(p) ? le['node'] : nil)}
end.sort { |a, b| a[:path] <=> b[:path] } end.sort_by { |e| e[:path] }
parents_ary = [] parents_ary = []
as_ary(le['parents']['parent']).map do |par| as_ary(le['parents']['parent']).map do |par|
parents_ary << par['__content__'] if par['__content__'] != "0000000000000000000000000000000000000000" parents_ary << par['__content__'] if par['__content__'] != "0000000000000000000000000000000000000000"
......
...@@ -168,7 +168,7 @@ module Redmine ...@@ -168,7 +168,7 @@ module Redmine
:from_revision => path['copyfrom-rev'] :from_revision => path['copyfrom-rev']
} }
end if logentry['paths'] && logentry['paths']['path'] end if logentry['paths'] && logentry['paths']['path']
paths.sort! { |x,y| x[:path] <=> y[:path] } paths.sort_by! {|e| e[:path]}
revisions << Revision.new({:identifier => logentry['revision'], revisions << Revision.new({:identifier => logentry['revision'],
:author => (logentry['author'] ? logentry['author']['__content__'] : ""), :author => (logentry['author'] ? logentry['author']['__content__'] : ""),
......
...@@ -2,7 +2,7 @@ namespace :redmine do ...@@ -2,7 +2,7 @@ namespace :redmine do
desc "List all permissions and the actions registered with them" desc "List all permissions and the actions registered with them"
task :permissions => :environment do task :permissions => :environment do
puts "Permission Name - controller/action pairs" puts "Permission Name - controller/action pairs"
Redmine::AccessControl.permissions.sort {|a,b| a.name.to_s <=> b.name.to_s }.each do |permission| Redmine::AccessControl.permissions.sort_by {|p| p.name.to_s}.each do |permission|
puts ":#{permission.name} - #{permission.actions.join(', ')}" puts ":#{permission.name} - #{permission.actions.join(', ')}"
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment