aussiegeek/rubyzip — pull request #39 by wpc (2012-03-26 17:04:12+00:00)
Title: Fix performance issue on reading zip file with large amount of entries.

I recently came cross reading/writing zip files with large amount small files, and found Zip::ZipFile.find_entry is really big performance bottom-neck for my app through profiling. This pull request try to resolve this problem by making zip entry lookup in Zip::ZipEntrySet as a hash lookup (O(n) -> O(1)). A side effect of this change is that now in Zip::ZipEntrySet entries with name "a_directory" and "a_directory/" will be stored as one entry. I guess that is fine because file and directory with same name can not co-exists in a zip file anyway.

I did a simple experiment, given a zip file with 35160 directories and files, execute following code under ruby 1.9.2, MacOSX 10.7:

```ruby
zipfile = Zip::ZipFile.open("./the_zip_file", Zip::ZipFile::CREATE)

zipfile.each do |entry|
if entry.ftype == :file
entry.get_input_stream { |s| s.readlines }
end
end
```
Before applying the patch:

```console
ruby read_test.rb 1340.08s user 13.23s system 100% cpu 22:28.38 total
```
After:

```console
ruby read_test.rb 28.48s user 0.77s system 100% cpu 29.203 total
```