[Rt-commit] r17028 - rt/3.8/trunk/share/html/Ticket/Elements

ruz at bestpractical.com ruz at bestpractical.com
Wed Nov 26 19:20:29 EST 2008


Author: ruz
Date: Wed Nov 26 19:20:28 2008
New Revision: 17028

Modified:
   rt/3.8/trunk/share/html/Ticket/Elements/ShowMessageStanza

Log:
* rewrite displaying message stanza without recursion to avoid
  problems with deep recursion errors and improve performance

Modified: rt/3.8/trunk/share/html/Ticket/Elements/ShowMessageStanza
==============================================================================
--- rt/3.8/trunk/share/html/Ticket/Elements/ShowMessageStanza	(original)
+++ rt/3.8/trunk/share/html/Ticket/Elements/ShowMessageStanza	Wed Nov 26 19:20:28 2008
@@ -45,30 +45,46 @@
 %# those contributions and any derivatives thereof.
 %# 
 %# END BPS TAGGED BLOCK }}}
-% if ( ref $Message ) {
-%    $m->out('<pre>') if $plain_text_pre && !$Depth;
-<div class="message-stanza-depth-<% $Depth %>">
 <%perl>
-my $para = '';
-foreach my $stanza ( @$Message) {
-    if ( ref $stanza eq "ARRAY" ) {
+if ( ref $Message ) {
+    $m->out('<pre>') if $plain_text_pre && !$Depth;
+    $m->out( qq{<div class="message-stanza-depth-$Depth">} );
+
+    my @stack;
+    my $para = '';
+    my $i = 0;
+
+    AGAIN: foreach ( ; $i < @$Message; $i++ ) {
+        my $stanza = $Message->[$i];
+        if ( ref $stanza eq "HASH" ) {
+            $para .= ( defined $stanza->{raw} ? $stanza->{raw} : '') ."\n";
+        }
+        next unless ref $stanza eq "ARRAY";
+
+        $print_content->( \$para ); $para = '';
+
+        $Depth++;
+        push @stack, [$Message, $i+1];
+        ($Message, $i) = ($stanza, -1);
+        $m->out( qq{<div class="message-stanza-depth-$Depth">} );
+    }
+    if ( length $para ) {
         $print_content->( \$para ); $para = '';
-        $m->comp( 'ShowMessageStanza',
-                  Depth   => $Depth + 1,
-                  Transaction => $Transaction,
-                  Message => $stanza );
     }
-    elsif ( ref $stanza eq "HASH" ) {
-        $para .= ( defined $stanza->{raw} ? $stanza->{raw} : '') ."\n";
+
+    if ( @stack ) {
+        ($Message, $i) = @{ pop @stack };
+        $Depth--;
+        $m->out('</div>');
+        goto AGAIN;
     }
+
+    $m->out('</div>');
+    $m->out('</pre>') if $plain_text_pre && !$Depth;
+} else {
+      $print_content->( \$Message );
 }
-$print_content->( \$para ) if length $para;
 </%perl>
-</div>
-% $m->out('</pre>') if $plain_text_pre && !$Depth;
-% } else {
-%       $print_content->( \$Message );
-% }
 <%INIT>
 my $plain_text_pre = RT->Config->Get('PlainTextPre', $session{'CurrentUser'});
 


More information about the Rt-commit mailing list