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
end
@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]}
@deliveries = ActionMailer::Base.perform_deliveries
......
......@@ -21,9 +21,9 @@ module ActivitiesHelper
def sort_activity_events(events)
events_by_group = events.group_by(&:event_group)
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)
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]
end
end
......
......@@ -20,6 +20,6 @@
module IssueRelationsHelper
def collection_for_relation_type_select
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
......@@ -269,7 +269,7 @@ module RepositoriesHelper
:href => block_given? ? yield(commit.scmid) : commit.scmid
}
end
heads.sort! { |head1, head2| head1.to_s <=> head2.to_s }
heads.sort_by!(&:to_s)
space = nil
heads.each do |head|
if commits_by_scmid.include? head.scmid
......
......@@ -55,7 +55,7 @@ module SearchHelper
def render_results_by_type(results_by_type)
links = []
# 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]
next if c == 0
text = "#{type_label(t)} (#{c})"
......
......@@ -118,7 +118,7 @@ class QueryCustomFieldColumn < QueryColumn
def value_object(object)
if custom_field.visible_by?(object.project, User.current)
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
nil
end
......
......@@ -619,7 +619,7 @@ module Redmine
end
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
def self.sort_issue_logic(issue)
......
......@@ -120,7 +120,7 @@ module Redmine
valid_languages.
select {|locale| ::I18n.exists?(:general_lang_name, locale)}.
map {|lang| [ll(lang.to_s, :general_lang_name), lang.to_s]}.
sort {|x,y| x.first <=> y.first }
sort_by(&:first)
else
ActionController::Base.cache_store.fetch "i18n/languages_options/#{Redmine::VERSION}" do
languages_options :cache => false
......
......@@ -206,7 +206,7 @@ module Redmine
:path => with_leading_slash(p),
:from_path => (cpmap.member?(p) ? with_leading_slash(cpmap[p]) : 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 = []
as_ary(le['parents']['parent']).map do |par|
parents_ary << par['__content__'] if par['__content__'] != "0000000000000000000000000000000000000000"
......
......@@ -168,7 +168,7 @@ module Redmine
:from_revision => path['copyfrom-rev']
}
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'],
:author => (logentry['author'] ? logentry['author']['__content__'] : ""),
......
......@@ -2,7 +2,7 @@ namespace :redmine do
desc "List all permissions and the actions registered with them"
task :permissions => :environment do
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(', ')}"
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