Permalink
Browse files

Avoid object creation/destruction when possible.

Object creation and destruction, even over a short time-frame, is expensive,
so where we can avoid it we should.

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>

Conflicts:
	lib/puppet/metatype/manager.rb

Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
  • Loading branch information...
Daniel Pittman
Daniel Pittman committed Jul 17, 2012
1 parent 5e3fbca commit 8173a6e6c199426381f1f9fb8d0a71e0d0c12f2a
Showing with 28 additions and 13 deletions.
  1. +16 −9 lib/puppet/metatype/manager.rb
  2. +9 −3 lib/puppet/parameter/value.rb
  3. +3 −1 lib/puppet/type.rb
@@ -108,17 +108,24 @@ def rmtype(name)
def type(name)
@types ||= {}
name = name.to_s.downcase.to_sym
if t = @types[name]
return t
else
if typeloader.load(name)
Puppet.warning "Loaded puppet/type/#{name} but no class was created" unless @types.include? name
end
# We are overwhelmingly symbols here, which usually match, so it is worth
# having this special-case to return quickly. Like, 25K to 300 symbols to
# strings in this method. --daniel 2012-07-17
return @types[name] if @types[name]
# Try mangling the name, if it is a string.
if name.is_a? String
name = name.downcase.intern
return @types[name] if @types[name]
end
return @types[name]
# Try loading the type.
if typeloader.load(name, Puppet::Node::Environment.current)
Puppet.warning "Loaded puppet/type/#{name} but no class was created" unless @types.include? name
end
# ...and I guess that is that, eh.
return @types[name]
end
# Create a loader for Puppet types.
@@ -53,11 +53,17 @@ def regex?
# A standard way of converting all of our values, so we're always
# comparing apples to apples.
def convert(value)
if value == ''
# We can't intern an empty string, yay.
case value
when Symbol, '' # can't intern an empty string
value
when String
value.intern
when true
:true
when false
:false
else
value.to_s.to_sym
value.to_s.intern
end
end
end
View
@@ -1880,7 +1880,9 @@ def parent
# Return the "type[name]" style reference.
def ref
"#{self.class.name.to_s.capitalize}[#{self.title}]"
# memoizing this is worthwhile ~ 3 percent of calls are the "first time
# around" in an average run of Puppet. --daniel 2012-07-17
@ref ||= "#{self.class.name.to_s.capitalize}[#{self.title}]"
end
def self_refresh?

0 comments on commit 8173a6e

Please sign in to comment.