From: Eric Wong <e@80x24.org>
To: spew@80x24.org
Subject: [PATCH] thread: avoid recursion
Date: Fri, 5 Aug 2016 00:24:18 +0000 [thread overview]
Message-ID: <20160805002418.7274-1-e@80x24.org> (raw)
(bug reported to CPAN RT, awaiting bug #)
---
lib/PublicInbox/Thread.pm | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/lib/PublicInbox/Thread.pm b/lib/PublicInbox/Thread.pm
index 44a565a..95627de 100644
--- a/lib/PublicInbox/Thread.pm
+++ b/lib/PublicInbox/Thread.pm
@@ -42,6 +42,31 @@ sub topmost {
$_[0]->SUPER::topmost || PublicInbox::Thread::CPANRTBug106498->new;
}
+sub recurse_down {
+ my ($self, $callback) = @_;
+ my %seen;
+ my @q = ($self);
+ while (my $cont = shift @q) {
+ $seen{$cont}++;
+ $callback->($cont);
+
+ if (my $next = $cont->next) {
+ if ($seen{$next}) {
+ $cont->next(undef);
+ } else {
+ push @q, $next;
+ }
+ }
+ if (my $child = $cont->child) {
+ if ($seen{$child}) {
+ $cont->child(undef);
+ } else {
+ push @q, $child;
+ }
+ }
+ }
+}
+
# ref:
# - http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=795913
# - https://rt.cpan.org/Ticket/Display.html?id=106498
--
EW
reply other threads:[~2016-08-05 0:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160805002418.7274-1-e@80x24.org \
--to=e@80x24.org \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).