diff options
author | Luke Kanies <luke@madstop.com> | 2009-02-13 00:46:45 -0600 |
---|---|---|
committer | James Turnbull <james@lovedthanlost.net> | 2009-02-28 09:16:42 +1100 |
commit | e2b406239eaa255c41acb31942169296bea71948 (patch) | |
tree | d2a667e474783122ed623646e04c5f1cdea0f996 /lib/puppet | |
parent | fa6494b69ad1b01a9c587c86aa1731f4702f5509 (diff) | |
download | puppet-e2b406239eaa255c41acb31942169296bea71948.tar.gz puppet-e2b406239eaa255c41acb31942169296bea71948.tar.xz puppet-e2b406239eaa255c41acb31942169296bea71948.zip |
Adding a performance optimization to the FileCollection.
I saw about a 7x speed increase when adding this simple
hash to speed up the file index lookup.
Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/file_collection.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/puppet/file_collection.rb b/lib/puppet/file_collection.rb index 69f59ffdf..7db2600c0 100644 --- a/lib/puppet/file_collection.rb +++ b/lib/puppet/file_collection.rb @@ -9,14 +9,16 @@ class Puppet::FileCollection def initialize @paths = [] + @inverse = {} end def index(path) - if @paths.include?(path) - return @paths.index(path) + if i = @inverse[path] + return i else @paths << path - return @paths.length - 1 + i = @inverse[path] = @paths.length - 1 + return i end end |