* [PATCH] thread: avoid recursion
@ 2016-08-05 0:24 Eric Wong
0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-08-05 0:24 UTC (permalink / raw)
To: spew
(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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2016-08-05 0:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-05 0:24 [PATCH] thread: avoid recursion Eric Wong
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).