[Rubygems-developers] Why does an install command an update

Hugh Sasse hgs at dmu.ac.uk
Sat Jun 4 09:47:51 EDT 2005


On Fri, 3 Jun 2005, Jim Freeze wrote:

> Nice optimization Hugh. More than double the savings.

Thanks.  I don't know if it will be useful though, because it
isn't backwards compatible.  [But then, neither is removing file
lists completely.]
>
> Here is a shorter version (don't know if it
> is windows compatible though):
>
>  --- ftest.rb	Fri Jun  3 15:12:01 2005
>  +++ ftest2.rb	Fri Jun  3 15:10:58 2005
>  @@ -18,13 +18,20 @@
>   puts files.to_yaml.size
>
>   def optimize_file_list(files)
>  -  hash = Hash.new { |h,k| h[k] = [] }
>  +  hash = {}
>     files.each { |file|
>  -    dir      = File.dirname(file)
>  -    filename = File.basename(file)
>  -    hash[dir] << filename
>  +    next if File.directory?(file)
>  +    a = file.split(/\//)

You mean [compatibility-wise] that line?  I think Pathname handles
that kind of thing portably.  I've heard something about Macs using
':' for directory separators, but maybe that's not true in MacOS X --
I don't know as I've never used a Mac

>  +    rtn = a.inject(hash) { |h,k| h[k] ||= {} }
>     }
>  -  hash
>  +  recurs = lambda { |h,k|
>  +    if h[k].empty?
>  +      h[k] = nil
>  +    else
>  +      h[k].each { |kk,vv| recurs.call(h[k], kk) }
>  +    end
>  +  }
>  +  hash.each { |k,v| recurs.call(hash,k) }

I think that will take more study on my part to figure that out :-)
Shorter is good, we may need to do speed trials as well.

>   end
>
>   files["files"] = optimize_file_list(files["files"])
>  ---
> The output is:
>
>  files:
>    - lib/cgikit
>    - lib/cgikit.rb
>    - lib/cgikit/components
>    - lib/cgikit/components/CKErrorPage
>    - lib/cgikit/components/CKErrorPage/CKErrorPage.ckd
>    - lib/cgikit/components/CKErrorPage/CKErrorPage.html
>    - lib/cgikit/components/CKErrorPage/CKErrorPage.rb
>  271
>  ---
>  files:
>    lib:
>      cgikit.rb:
>      cgikit:
>        components:
>          CKErrorPage:
>            CKErrorPage.ckd:
>            CKErrorPage.html:
>            CKErrorPage.rb:
>  174
>
> I get the same 36% savings as you did, so it looks to be the same.

Looks the same to me.  I think Jim Weirich needs to step in and tell
us how this may (not) fit in with how he plans tp proceed, before we
get to somewhere really esoteric.

         Hugh



More information about the Rubygems-developers mailing list