On 09/07/2009 01:05 PM, Stefan Schubert wrote:
> ref: refs/heads/master
> commit 32be3734b62d83a68169620cf8ebaa8b5f4908e8
> Author: Stefan Schubert <[email protected]>
> Date: Mon Sep 7 13:05:09 2009 +0200
>
> more readable
> ---
> .../app/controllers/patch_updates_controller.rb | 2 +-
> 1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git
> a/plugins/patch_updates/app/controllers/patch_updates_controller.rb
> b/plugins/patch_updates/app/controllers/patch_updates_controller.rb
> index 4747342..10daa3e 100644
> --- a/plugins/patch_updates/app/controllers/patch_updates_controller.rb
> +++ b/plugins/patch_updates/app/controllers/patch_updates_controller.rb
> @@ -29,7 +29,7 @@ class PatchUpdatesController < ApplicationController
> patches_summary = { :security => 0, :important => 0, :optional => 0}
>
> [:security, :important, :optional].each do |patch_type|
> - patches_summary[patch_type] = patch_updates.collect { |p| p.kind ==
> patch_type.to_s ? p : nil }.nitems
> + patches_summary[patch_type] = patch_updates.find_all { |p| p.kind ==
> patch_type.to_s }.size
Hi, little note to efficiency. This code iterate through patch_updates
three times, creates three array for which then get size.
I think that better is iterate only once and add size to.
So you can instead
[:security, :important, :optional].each do |patch_type|
patches_summary[patch_type] = patch_updates.find_all { |p| p.kind
== patch_type.to_s }.size
use (you already init it to zero in hash initializer)
patch_updates.each { |pu| patches_summary[pu.kind.to_sym] += 1 }
you get some result, efficienty and I think that it is has same readability.
--
Josef Reidinger
YaST team
maintainer of perl-Bootloader, YaST2-Repair, webyast modules language
and time
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]