+1, that's a real good idea.

On Mon, 2011-01-03 at 16:31 -0800, Jesse Wolfe wrote:
> Ruby's default #inspect method can lead to printing factorial-order
> output for large graphs of objects. Since we have large graphs of
> objects, this is not optimal.
> This patch replaces a few well-connected objects' #inspect methods with
> methods that produce reduced output, and are thus much faster.
> 
> Paired-With: Nick Lewis <[email protected]>
> Signed-off-by: Jesse Wolfe <[email protected]>
> ---
>  lib/puppet/parser/ast.rb               |    4 ++++
>  lib/puppet/relationship.rb             |    4 ++++
>  lib/puppet/resource.rb                 |    4 ++++
>  lib/puppet/resource/type_collection.rb |    4 ++++
>  lib/puppet/simple_graph.rb             |    4 ++++
>  5 files changed, 20 insertions(+), 0 deletions(-)
> 
> diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
> index 54e034a..a5aaedd 100644
> --- a/lib/puppet/parser/ast.rb
> +++ b/lib/puppet/parser/ast.rb
> @@ -19,6 +19,10 @@ class Puppet::Parser::AST
>  
>    attr_accessor :parent, :scope
>  
> +  def inspect
> +    "( #{self.class} #{self.to_s} #[email protected]} )"
> +  end
> +
>    # don't fetch lexer comment by default
>    def use_docs
>      self.class.use_docs
> diff --git a/lib/puppet/relationship.rb b/lib/puppet/relationship.rb
> index 7079fb4..08d7d04 100644
> --- a/lib/puppet/relationship.rb
> +++ b/lib/puppet/relationship.rb
> @@ -71,6 +71,10 @@ class Puppet::Relationship
>      "#{source} => #{target}"
>    end
>  
> +  def inspect
> +    "{ #{source} => #{target} }"
> +  end
> +
>    def to_pson_data_hash
>      data = {
>        'source' => source.to_s,
> diff --git a/lib/puppet/resource.rb b/lib/puppet/resource.rb
> index 4f0d507..b0a3ece 100644
> --- a/lib/puppet/resource.rb
> +++ b/lib/puppet/resource.rb
> @@ -46,6 +46,10 @@ class Puppet::Resource
>      resource
>    end
>  
> +  def inspect
> +    "#...@type}[#{@title}]#{to_hash.inspect}"
> +  end
> +
>    def to_pson_data_hash
>      data = ([:type, :title, :tags] + ATTRIBUTES).inject({}) do |hash, param|
>        next hash unless value = self.send(param)
> diff --git a/lib/puppet/resource/type_collection.rb 
> b/lib/puppet/resource/type_collection.rb
> index 6a03458..277d37b 100644
> --- a/lib/puppet/resource/type_collection.rb
> +++ b/lib/puppet/resource/type_collection.rb
> @@ -19,6 +19,10 @@ class Puppet::Resource::TypeCollection
>      @watched_files = {}
>    end
>  
> +  def inspect
> +    "TypeCollection" + { :hostclasses => @hostclasses.keys, :definitions => 
> @definitions.keys, :nodes => @nodes.keys }.inspect
> +  end
> +
>    def <<(thing)
>      add(thing)
>      self
> diff --git a/lib/puppet/simple_graph.rb b/lib/puppet/simple_graph.rb
> index 55b39fa..c5dac0f 100644
> --- a/lib/puppet/simple_graph.rb
> +++ b/lib/puppet/simple_graph.rb
> @@ -80,6 +80,10 @@ class Puppet::SimpleGraph
>        vertex.to_s
>      end
>  
> +    def inspect
> +      { :@adjacencies => @adjacencies, :@vertex => @vertex.to_s }.inspect
> +    end
> +
>      private
>  
>      # These methods exist so we don't need a Hash with a default proc.
> -- 
> 1.7.0.4
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to