diff options
author | Luke Kanies <luke@puppetlabs.com> | 2010-04-13 12:16:05 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 0d4fd60c7c143cc1f4e4b0f99f359c09cbfbf21e (patch) | |
tree | a3fe5f41897cbc7e30507877818cf5150630fc67 /lib/puppet/parser/compiler.rb | |
parent | 047ebfee96aa6c9471883a71fef4f3a4086cd149 (diff) | |
download | puppet-0d4fd60c7c143cc1f4e4b0f99f359c09cbfbf21e.tar.gz puppet-0d4fd60c7c143cc1f4e4b0f99f359c09cbfbf21e.tar.xz puppet-0d4fd60c7c143cc1f4e4b0f99f359c09cbfbf21e.zip |
Fixing #1903 - metaparam inheritance is much faster
This doesn't actually fix the specific request in #1903,
which said there should be no inheritance at all, but
I've changed my mind on that. Static inheritance is good,
it should just be faster.
This change could result in up to 70% speed improvements
in compiling.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet/parser/compiler.rb')
-rw-r--r-- | lib/puppet/parser/compiler.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/puppet/parser/compiler.rb b/lib/puppet/parser/compiler.rb index fd7d9680b..ae4af7622 100644 --- a/lib/puppet/parser/compiler.rb +++ b/lib/puppet/parser/compiler.rb @@ -361,6 +361,50 @@ class Puppet::Parser::Compiler resource.finish if resource.respond_to?(:finish) end + + add_resource_metaparams + end + + def add_resource_metaparams + unless main = catalog.resource(:class, :main) + raise "Couldn't find main" + end + + names = [] + Puppet::Type.eachmetaparam do |name| + next if Puppet::Parser::Resource.relationship_parameter?(name) + names << name + end + + data = {} + catalog.walk(main, :out) do |source, target| + if source_data = data[source] || metaparams_as_data(source, names) + # only store anything in the data hash if we've actually got + # data + data[source] ||= source_data + source_data.each do |param, value| + target[param] = value if target[param].nil? + end + data[target] = source_data.merge(metaparams_as_data(target, names)) + end + + target.tag(*(source.tags)) + end + end + + def metaparams_as_data(resource, params) + data = nil + params.each do |param| + unless resource[param].nil? + # Because we could be creating a hash for every resource, + # and we actually probably don't often have any data here at all, + # we're optimizing a bit by only creating a hash if there's + # any data to put in it. + data ||= {} + data[param] = resource[param] + end + end + data end # Initialize the top-level scope, class, and resource. |