From: Christian Walde Date: Mon, 11 May 2015 15:03:33 +0000 (+0200) Subject: prevent debug calls with expensive arguments if debugging is not enabled X-Git-Tag: v0.11022~45 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FSQL-Translator.git;a=commitdiff_plain;h=fce0f0b5b8782189bf6f15b01b590fa135097dc1 prevent debug calls with expensive arguments if debugging is not enabled 15-05-11@16:58:43 (ribasushi) just optimize for "minimal logical diff", and ignore the urge to "strive for elegance" --- diff --git a/Changes b/Changes index b8c9bda..728a6a1 100644 --- a/Changes +++ b/Changes @@ -2,6 +2,7 @@ Changes for SQL::Translator * Add support for monotonically increasing SQLite autoincs (GH#47) * Declare dependencies in deterministic order (RT#102859) + * Multiple speedups of naive internal debugging mechanism * Remove dependency on List::MoreUtils ( http://is.gd/lmu_cac_debacle ) 0.11021 2015-01-29 diff --git a/lib/SQL/Translator.pm b/lib/SQL/Translator.pm index 1f0c636..1cbfcee 100644 --- a/lib/SQL/Translator.pm +++ b/lib/SQL/Translator.pm @@ -148,7 +148,7 @@ has filters => ( next; } else { - __PACKAGE__->debug("Adding $filt filter. Args:".Dumper(\@args)."\n"); + __PACKAGE__->debug("Adding $filt filter. Args:".Dumper(\@args)."\n") if __PACKAGE__->debugging; $filt = _load_sub("$filt\::filter", "SQL::Translator::Filter") || throw(__PACKAGE__->error); push @filters, [$filt,@args]; @@ -361,7 +361,7 @@ sub translate { return $self->error($msg); } } - $self->debug("Schema =\n", Dumper($self->schema), "\n"); + $self->debug("Schema =\n", Dumper($self->schema), "\n") if $self->debugging;; # Validate the schema if asked to. if ($self->validate) { diff --git a/lib/SQL/Translator/Producer/Diagram.pm b/lib/SQL/Translator/Producer/Diagram.pm index f415390..a12556b 100644 --- a/lib/SQL/Translator/Producer/Diagram.pm +++ b/lib/SQL/Translator/Producer/Diagram.pm @@ -67,8 +67,8 @@ sub produce { my $schema = $t->schema; my $args = $t->producer_args; local $DEBUG = $t->debug; - debug("Schema =\n", Dumper( $schema )); - debug("Producer args =\n", Dumper( $args )); + debug("Schema =\n", Dumper( $schema )) if $DEBUG; + debug("Producer args =\n", Dumper( $args )) if $DEBUG; my $out_file = $args->{'out_file'} || ''; my $output_type = $args->{'output_type'} || 'png'; @@ -176,7 +176,7 @@ sub produce { debug("Processing table '$table_name'"); my @fields = $table->get_fields; - debug("Fields = ", join(', ', map { $_->name } @fields)); + debug("Fields = ", join(', ', map { $_->name } @fields)) if $DEBUG; my ( @fld_desc, $max_name, $max_desc ); for my $f ( @fields ) { diff --git a/lib/SQL/Translator/Producer/GraphViz.pm b/lib/SQL/Translator/Producer/GraphViz.pm index f17a9d3..3b8ef59 100644 --- a/lib/SQL/Translator/Producer/GraphViz.pm +++ b/lib/SQL/Translator/Producer/GraphViz.pm @@ -520,7 +520,7 @@ sub produce { debug("Processing table '$table_name'"); - debug("Fields = ", join(', ', map { $_->name } @fields)); + debug("Fields = ", join(', ', map { $_->name } @fields)) if $DEBUG; for my $f ( @fields ) { my $name = $f->name or next; diff --git a/lib/SQL/Translator/Producer/TTSchema.pm b/lib/SQL/Translator/Producer/TTSchema.pm index 5885d3b..36f62b6 100644 --- a/lib/SQL/Translator/Producer/TTSchema.pm +++ b/lib/SQL/Translator/Producer/TTSchema.pm @@ -138,7 +138,7 @@ sub produce { my %tt_conf = exists $args->{tt_conf} ? %{$args->{tt_conf}} : (); # sqlt passes the producer args for _all_ producers in, so we use this # grep hack to test for the old usage. - debug(Dumper(\%tt_conf)); + debug(Dumper(\%tt_conf)) if $DEBUG; if ( grep /^[A-Z_]+$/, keys %$args ) { warn "Template config directly in the producer args is deprecated." ." Please use 'tt_conf' instead.\n";