Просмотр исходного кода

Make debugging faster both when turned on and off - dosn't check if debugging is enabled for every debug call

sbingner 25 лет назад
Родитель
Сommit
0fe63f8a62
1 измененных файлов с 19 добавлено и 17 удалено
  1. 19 17
      pisg.pl

+ 19 - 17
pisg.pl

@@ -115,7 +115,7 @@ $thirdline, $processtime, @topics, %monologue, %kicked, %gotkick,
 %lastused, %gotban, %setban, %foul, $days, $oldtime, $lastline, $actions,
 %lastused, %gotban, %setban, %foul, $days, $oldtime, $lastline, $actions,
 $normals, %T, $repeated, $lastnormal, %shout, %slap, %slapped, %words,
 $normals, %T, $repeated, $lastnormal, %shout, %slap, %slapped, %words,
 %line_time, @urls, %urlnick, %kickline, %actionline, %shoutline, %slapline,
 %line_time, @urls, %urlnick, %kickline, %actionline, %shoutline, %slapline,
-%slappedline);
+%slappedline, $debug);
 
 
 
 
 sub main
 sub main
@@ -344,7 +344,7 @@ sub init_config
                     unless (($conf->{$var} eq $2) || $conf->{cmdl}{$var}) {
                     unless (($conf->{$var} eq $2) || $conf->{cmdl}{$var}) {
                         $conf->{$var} = $2;
                         $conf->{$var} = $2;
                     }
                     }
-                    debug("Conf: $var = $2");
+                    $debug->("Conf: $var = $2");
                 }
                 }
 
 
             } elsif ($line =~ /<channel=['"]([^'"]+)['"](.*)>/i) {
             } elsif ($line =~ /<channel=['"]([^'"]+)['"](.*)>/i) {
@@ -354,7 +354,7 @@ sub init_config
                 while ($settings =~ s/\s([^=]+)=["']([^"']*)["']//) {
                 while ($settings =~ s/\s([^=]+)=["']([^"']*)["']//) {
                     my $var = lc($1);
                     my $var = lc($1);
                     $chans->{$channel}{$var} = $2;
                     $chans->{$channel}{$var} = $2;
-                    debug("Channel conf $channel: $var = $2");
+                    $debug->("Channel conf $channel: $var = $2");
                 }
                 }
                 while (<CONFIG>) {
                 while (<CONFIG>) {
                     last if ($_ =~ /<\/*channel>/i);
                     last if ($_ =~ /<\/*channel>/i);
@@ -363,7 +363,7 @@ sub init_config
                         unless ($conf->{cmdl}{$var}) {
                         unless ($conf->{cmdl}{$var}) {
                             $chans->{$channel}{$var} = $2;
                             $chans->{$channel}{$var} = $2;
                         }
                         }
-                        debug("Conf $channel: $var = $2");
+                        $debug->("Conf $channel: $var = $2");
                     }
                     }
                 }
                 }
             }
             }
@@ -386,7 +386,7 @@ sub init_debug
         print "[ Debugging => $conf->{debugfile} ]\n";
         print "[ Debugging => $conf->{debugfile} ]\n";
         open(DEBUG,"> $conf->{debugfile}") or print STDERR "$0: Unable to open debug
         open(DEBUG,"> $conf->{debugfile}") or print STDERR "$0: Unable to open debug
         file($conf->{debugfile}): $!\n";
         file($conf->{debugfile}): $!\n";
-        debug("*** pisg debug file for $conf->{logfile}\n");
+        $debug->("*** pisg debug file for $conf->{logfile}\n");
         if ($conf->{debugqueue}) {
         if ($conf->{debugqueue}) {
             print DEBUG $conf->{debugqueue};
             print DEBUG $conf->{debugqueue};
             delete $conf->{debugqueue};
             delete $conf->{debugqueue};
@@ -644,7 +644,7 @@ sub parse_normalline
     my %hash;
     my %hash;
 
 
     if ($line =~ /$normalline/) {
     if ($line =~ /$normalline/) {
-        debug("[$lines] Normal: $1 $2 $3");
+        $debug->("[$lines] Normal: $1 $2 $3");
 
 
         if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
         if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
         'eggdrop') || ($conf->{format} eq 'bxlog') || ($conf->{format} eq 'grufti')) {
         'eggdrop') || ($conf->{format} eq 'bxlog') || ($conf->{format} eq 'grufti')) {
@@ -671,7 +671,7 @@ sub parse_actionline
     my %hash;
     my %hash;
 
 
     if ($line =~ /$actionline/) {
     if ($line =~ /$actionline/) {
-        debug("[$lines] Action: $1 $2 $3");
+        $debug->("[$lines] Action: $1 $2 $3");
 
 
         if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
         if (($conf->{format} eq 'mIRC') || ($conf->{format} eq 'xchat') || ($conf->{format} eq
         'eggdrop') || $conf->{format} eq 'bxlog' || ($conf->{format} eq 'grufti')) {
         'eggdrop') || $conf->{format} eq 'bxlog' || ($conf->{format} eq 'grufti')) {
@@ -710,11 +710,11 @@ sub parse_thirdline
 
 
     if ($line =~ /$thirdline/) {
     if ($line =~ /$thirdline/) {
         if ($7) {
         if ($7) {
-          debug("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
+          $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6 $7");
         } elsif ($5) {
         } elsif ($5) {
-          debug("[$lines] ***: $1 $2 $3 $4 $5 $6");
+          $debug->("[$lines] ***: $1 $2 $3 $4 $5 $6");
         } else {
         } else {
-          debug("[$lines] ***: $1 $2 $3 $4");
+          $debug->("[$lines] ***: $1 $2 $3 $4");
         }
         }
 
 
 
 
@@ -1009,9 +1009,9 @@ sub replace_links
 
 
 }
 }
 
 
-sub debug
-{
-    if ($conf->{debug}) {
+if ($conf->{debug}) {
+    $debug = sub
+    {
         my $debugline = $_[0] . "\n";
         my $debugline = $_[0] . "\n";
         if ($conf->{debugstarted}) {
         if ($conf->{debugstarted}) {
             print DEBUG $debugline;
             print DEBUG $debugline;
@@ -1019,6 +1019,8 @@ sub debug
             $conf->{debugqueue} .= $debugline;
             $conf->{debugqueue} .= $debugline;
         }
         }
     }
     }
+} else {
+    $debug = sub {};
 }
 }
 
 
 sub find_alias
 sub find_alias
@@ -1130,10 +1132,10 @@ sub activetimes
     my $image;
     my $image;
 
 
     for my $hour (sort keys %times) {
     for my $hour (sort keys %times) {
-        debug("Time: $hour => ". $times{$hour});
+        $debug->("Time: $hour => ". $times{$hour});
         $image = "pic_v_".(int($hour/6)*6);
         $image = "pic_v_".(int($hour/6)*6);
         $image = $conf->{$image};
         $image = $conf->{$image};
-        debug("Image: $image");
+        $debug->("Image: $image");
 
 
         my $size = ($times{$hour} / $highest_value) * 100;
         my $size = ($times{$hour} / $highest_value) * 100;
         my $percent = ($times{$hour} / $lines) * 100;
         my $percent = ($times{$hour} / $lines) * 100;
@@ -1337,7 +1339,7 @@ sub user_linetimes {
             $bar .= "<img src=\"$conf->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">";
             $bar .= "<img src=\"$conf->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\">";
         }
         }
     }
     }
-    debug("Length='$len', Sum='$debuglen'");
+    $debug->("Length='$len', Sum='$debuglen'");
     return "$bar&nbsp;$line{$nick}";
     return "$bar&nbsp;$line{$nick}";
 }
 }
 
 
@@ -2178,7 +2180,7 @@ sub mostsmiles
 
 
 sub lasttopics
 sub lasttopics
 {
 {
-    debug("Total number of topics: ". scalar @topics);
+    $debug->("Total number of topics: ". scalar @topics);
 
 
     my %hash = (
     my %hash = (
 	    total => scalar @topics
 	    total => scalar @topics